package octez-shell-libs

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type

Function evaluation in a detached process

This library uses a process detached in a separated unix process to execute a given function, with bidirectional communication channels and transmission of the function result at the end of the execution.

The communication channels does not require a data encoding, but the data encoding can be given. In absence of data encoding the Marshal mecanism will be used. Be aware that extensible types, like error or exception cannot be safely exchanged between processes.

Flags for Marshal serialisation can be passed at the creation of the detached process.

exception Exited of int
module Channel : sig ... end

Endpoint of a bidirectionnal channel.

type ('sent, 'received, 'result) t

Detached process.

val detach : ?prefix:string -> ?canceler:Lwt_canceler.t -> ?input_encoding:'received Tezos_base.TzPervasives.Data_encoding.encoding -> ?output_encoding:'sent Tezos_base.TzPervasives.Data_encoding.encoding -> ?value_encoding:'result Tezos_base.TzPervasives.Data_encoding.encoding -> ?flags:Stdlib.Marshal.extern_flags list -> (('sent, 'received) Channel.t -> 'result Tezos_base.TzPervasives.Error_monad.tzresult Lwt.t) -> ('sent, 'received, 'result) t Tezos_base.TzPervasives.Error_monad.tzresult Lwt.t

Executing a function in a detached process. prefix will be used in detached process logs. On canceling of canceler, the detached process will be killed by SIGKILL.

input_encoding and output_encoding, if provided, will be used to exchange values between the main process and the detached process input_encoding is for values received by the detached process. output_encoding is for values sent by the detached process.

In absence of data encoding the Marshal mecanism will be used. Be aware that extensible types, like error or exception cannot be safely exchanged between processes.

value_encoding is for the encoding of the result of the detached function. The Error_monad encapsulation part of the value computed by the detached function will be safely encoded, even without encoding for the 'result type. Ie if the detached function end with an error, the error will safely be serialized-deserialised.

If no encoding is given, the values will be serialized using the Marshal module, with the given flags (if any is provided).

val send : ('a, 'received, 'c) t -> 'received -> unit Tezos_base.TzPervasives.Error_monad.tzresult Lwt.t

Sending a data to the detached process

val receive : ('sent, 'b, 'c) t -> 'sent Tezos_base.TzPervasives.Error_monad.tzresult Lwt.t

Receiving a data from the detached process. This call is blocking.

val wait_result : ('a, 'b, 'result) t -> 'result Tezos_base.TzPervasives.Error_monad.tzresult Lwt.t

Receiving the result of the detached function. This call is blocking.

Working with list of detached process

val wait_all_results : ('a, 'b, 'c) t list -> 'c list Tezos_base.TzPervasives.Error_monad.tzresult Lwt.t

Waiting for all the detached function to finish, unless one of the function return an error.

If all detached functions succesfully compute a value, return the list of values.

If at least one function end with en error, cancel all the unfinished process, and return the trace of errors of unsuccesful process.

val wait_all : ('a, 'b, 'c) t list -> unit Tezos_base.TzPervasives.Error_monad.tzresult Lwt.t

Waiting for all the detached function to finish, unless one of the function return an error.

If all detached functions succesfully compute a value, return unit.

If at least one function end with en error, cancel all the unfinished process, and fail with a message containing all the errors.

OCaml

Innovation. Community. Security.