Module Tezos_p2p.P2p_workers

This module defines a simple interface that help writing generic workers used in lib_p2p, and avoid redundancy in their implementation.

In general, there exists a single worker of a kind that is devoted to a specific task, and is basically an infinite loop. The loop is handled through a Callback kind that returns instantaneously, and the handler is responsible for sleeping and resume.

P2P workers are generally created (for their state to exist) and activated (starting their worker loop) in two phases, which slightly differs from workers that are launched directly. These workers emulate this semantics on top of Tezos_workers.

module type COMPONENT = sig ... end

This functor generates a Name module out of a base, and generates a name for unique workers: once a worker has been spawned from a table, no other worker can be spawned again.

module type P2P_REQUEST = sig ... end

Module signature that is equivalent to the Tezos_base.Worker_intf.REQUEST with view being explicit.

type ('response, 'error) loop =
  1. | Loop : (unit, Tezos_base.TzPervasives.tztrace) loop
module Loop_request : P2P_REQUEST with type ('response, 'error) t = ('response, 'error) loop

The request for P2P workers is generally not useful. This module can be used as a P2p_request that serve only to loop again and return its result by a callback.

The functor generates a valid Worker, using P2p_request for requests. However, it is recommended to use the activated_worker kind as it enables decoupling creation of the state and activation of the loop.