package lsp

  1. Overview
  2. Docs
LSP protocol implementation in OCaml

Install

Dune Dependency

Authors

Maintainers

Sources

jsonrpc-1.4.1.tbz
sha256=cee8371e7048e24c90e916c373ef6f3aba6f474d8a5fcf507ab6650fd8575eeb
sha512=150ebf71d3484d3beec1a145877cf30d84581bd072dd20159e878ed07cc4fc647b019b98bb0c9fede839b87f7bd13de4a64b534c0760a2ec57d0e4a4deac6f0f

doc/lsp.fiber/Fiber/index.html

Module FiberSource

Concurrency library

This module implements "structured concurrency".

Generals

Sourcetype 'a t

Type of fiber. A fiber represent a suspended computation. Note that using the same fiber twice will execute it twice, which is probably not what you want. To share the result of a fiber, use an Ivar.t.

Sourceval return : 'a -> 'a t

Create a fiber that has already terminated.

Sourceval of_thunk : (unit -> 'a t) -> 'a t

Converts a thunk to a fiber, making sure the thunk runs in the context of the fiber (rather than applied in the current context).

Equivalent to (>>=) (return ()), but more explicit.

Sourceval never : 'a t

Fiber that never completes.

Sourcemodule O : sig ... end
Sourceval map : 'a t -> f:('a -> 'b) -> 'b t
Sourceval bind : 'a t -> f:('a -> 'b t) -> 'b t

Joining

The following combinators are helpers to combine the result of several fibers into one. Note that they do not introduce parallelism.

Sourceval both : 'a t -> 'b t -> ('a * 'b) t
Sourceval sequential_map : 'a list -> f:('a -> 'b t) -> 'b list t
Sourceval sequential_iter : 'a list -> f:('a -> unit t) -> unit t

Forking + joining

The following functions combine forking 2 or more fibers followed by joining the results. The execution of the various fibers might be interleaved, however once the combining fiber has terminated, it is guaranteed that there are no fibers lingering around.

Sourceval fork_and_join : (unit -> 'a t) -> (unit -> 'b t) -> ('a * 'b) t

Start two fibers and wait for their results.

Sourceval fork_and_join_unit : (unit -> unit t) -> (unit -> 'a t) -> 'a t

Same but assume the first fiber returns unit.

Sourceval parallel_map : 'a list -> f:('a -> 'b t) -> 'b list t

Map a list in parallel.

Sourceval parallel_iter : 'a list -> f:('a -> unit t) -> unit t

Iter over a list in parallel.

Local storage

Sourcemodule Var : sig ... end

Variables local to a fiber

Error handling

Sourceval with_error_handler : (unit -> 'a t) -> on_error:(Stdune.Exn_with_backtrace.t -> unit) -> 'a t

with_error_handler f ~on_error calls on_error for every exception raised during the execution of f. This include exceptions raised when calling f () or during the execution of fibers after f () has returned. Exceptions raised by on_error are passed on to the parent error handler.

It is guaranteed that after the fiber has returned a value, on_error will never be called.

Sourceval fold_errors : (unit -> 'a t) -> init:'b -> on_error:(Stdune.Exn_with_backtrace.t -> 'b -> 'b) -> ('a, 'b) Stdune.Result.t t

fold_errors f ~init ~on_error calls on_error for every exception raised during the execution of f. This include exceptions raised when calling f () or during the execution of fibers after f () has returned.

Exceptions raised by on_error are passed on to the parent error handler.

Sourceval collect_errors : (unit -> 'a t) -> ('a, Stdune.Exn_with_backtrace.t list) Stdune.Result.t t

collect_errors f is: fold_errors f ~init:[] ~on_error:(fun e l -> e :: l)

Sourceval finalize : (unit -> 'a t) -> finally:(unit -> unit t) -> 'a t

finalize f ~finally runs finally after f () has terminated, whether it fails or succeeds.

Synchronization

Sourcemodule Ivar : sig ... end

Write once variables

Sourcemodule Mvar : sig ... end

Mailbox variables

Sourcemodule Mutex : sig ... end
Sourcemodule Throttle : sig ... end

Limit the number of jobs

Sourcemodule Sequence : sig ... end

Running fibers

Sourcetype fill =
  1. | Fill : 'a Ivar.t * 'a -> fill
Sourceval run : 'a t -> iter:(unit -> fill) -> 'a

run t ~iter runs a fiber until it terminates. iter is used to implement the scheduler, it should block waiting for an event and return an ivar to fill.

Sourceval fork_and_race : (unit -> 'a t) -> (unit -> 'b t) -> ('a, 'b) Stdune.Either.t t
OCaml

Innovation. Community. Security.