Questions tagged [ocaml-lwt]

Use for questions regarding Lwt, an OCaml promise and concurrent programming library.

Lwt is 's concurrent programming library. It provides a single data type: the promise, which is a value that will become determined in the future. Creating a promise spawns a computation. When that computation is I/O, Lwt runs it in parallel with your OCaml code.

OCaml code, including creating and waiting on promises, is run in a single thread by default, so you don't have to worry about locking or preemption. You can detach code to be run in separate threads on an opt-in basis.

Useful resources

49 questions
1
vote
1 answer

Lwt.backtrace_* functions

I've just noticed the following functions in Lwt.mli: val backtrace_bind : (exn -> exn) -> 'a t -> ('a -> 'b t) -> 'b t val backtrace_catch : (exn -> exn) -> (unit -> 'a t) -> (exn -> 'a t) -> 'a t val backtrace_try_bind : (exn -> exn) -> (unit ->…
Antoine
  • 1,782
  • 1
  • 14
  • 32
1
vote
1 answer

Proper use of Lwt_main.run()

I have encountered some errors when using Lwt_main.run(). Basically I have two infinite loops with type unit -> 'a Lwt.t = and when I start both loops I receive errors. I am using these in the context that one loop is a writer loop and the…
Thomas
  • 347
  • 3
  • 19
1
vote
1 answer

How to use Lwt_pool

I want to have a pool of Redis database connections with a max number of connections. It looks like Lwt_pool is the solution I am looking for, but I don't quite grasp how it should work. For example, some questions I have: The docs talk about…
Sergi Mansilla
  • 12,495
  • 10
  • 39
  • 48
1
vote
2 answers

Using Core and Lwt together

I am using Core and Lwt together in a library I am working on. Core has good modules I'm familiar with and I'm more comfortable with Lwt threads. Is this a common thing to do? Is there any strong reason not to do that and instead use, let's say,…
Sergi Mansilla
  • 12,495
  • 10
  • 39
  • 48
1
vote
1 answer

Lwt and database access

I can't get my database access work with lwt. Should I include it in a thread? How? Or make a new thread which returns a 'a lwt value? If so, what to do with that value? The same goes for Printf.eprintf, which also seems to be blocked by lwt. So I…
Olle Härstedt
  • 3,799
  • 1
  • 24
  • 57
1
vote
1 answer

How to enable syntax color and indention for lwt in Emacs Tuareg mode?

I am using Tuareg mode for Emacs. I am also using lwt. lwt has some syntax extension, but Tuareg cannot recognize them and it is ugly without indention and coloring. I found…
Jackson Tale
  • 25,428
  • 34
  • 149
  • 271
1
vote
1 answer

How to fully utilise `lwt` in this case

Here is what I am going to do: I have a list of task and I need to run them all every 1 hour (scheduling). All those tasks are similar. for example, for one task, I need to download some data from a server (using http protocol and would take 5 - 8…
Jackson Tale
  • 25,428
  • 34
  • 149
  • 271
0
votes
1 answer

Problem with retransmitting stdin to a server in OCaml

I'm trying to write an IRC inspired server along with a client capable of communicating with it as a part of my uni class. I already wrote a server with which i can successfully interact using tools such as telnet. I'm having trouble with writing a…
0
votes
0 answers

Lwt error sending messages with capnproto

I am using capnproto to send messages between several nodes. Each node can both send and receive messages from all others. The relevant code looks like this: main.ml: let start_node id nodes = Lwt_main.run begin let listen_address = `TCP…
Melkor
  • 779
  • 1
  • 12
  • 29
0
votes
1 answer

This expression has type H2_lwt_unix.Client.t but an expression was expected of type 'weak702 Lwt.t

How to deal with 'a Lwt objects in a function? My code is Array.map (fun conn -> let* resp = (call_server conn (RequestVoteArg({ candidateNumber = myState.myPersistentState.id; term =…
Murphy
  • 47
  • 7
0
votes
1 answer

LWT installation failed using OPAM

LWT installation failed using OPAM on Ubuntu Server Information - Distributor ID: Ubuntu, Description: Ubuntu 18.04.4, LTS Release: 18.04, Codename: bionic Steps I followed - opam list -a # List the available packages opam…
joydeba
  • 778
  • 1
  • 9
  • 24
0
votes
1 answer

OCaml - Parmap executing Lwt threads hangs on the execution

This is a follow up to this question: How to synchronously execute an Lwt thread I am trying to run the following piece of code: open Lwt open Cohttp_lwt_unix let server_content2 x = "in server content x" |> print_endline ; Client.get…
zajer
  • 649
  • 6
  • 17
0
votes
1 answer

How to synchronously execute an Lwt thread

Is there any way to synchronously execute a thread made with Lwt library? To be specific, I am trying to run a series of post requests to a server that compute some value and returns a result. Based on answers provided to this question: How do I…
zajer
  • 649
  • 6
  • 17
0
votes
1 answer

How to make a loop break when using Lwt in OCaml

I'm writing code to monitor the content of a file. When the program reaches the end of the the file I want it to terminate cleanly. let log () : input_channel Lwt.t = openfile "log" [O_RDONLY] 0 >>= fun fd -> Lwt.return (of_fd input…
Addem
  • 3,635
  • 3
  • 35
  • 58
0
votes
0 answers

Creating a Chat Server

I am creating a chat server in the Ocaml language using lwt. What I want it to be able to do is prompt the user to enter a nickname, store the nickname, and then output that the user has joined the chat. I have already tried implementing my own…