eliom icon indicating copy to clipboard operation
eliom copied to clipboard

client: Direct-style API for `Eliom_comet` and `Eliom_bus`

Open Julow opened this issue 6 months ago • 1 comments

This changes the client-side API of Eliom_comet and Eliom_bus to be more compatible with direct-style programming:

  • Add a new callback-based API, Eliom_bus.register, which avoids using Lwt_stream internally. Eliom_bus.stream is re-implemented against the register API. Eliom_bus.original_stream is not re-implemented yet.

  • Eliom_comet.Channel is an abstract type instead of a Lwt_stream. Lwt_stream is difficult to migrate to other concurrency libraries because of its vast API and its many usecases. It's also callback-based but it's made to be easy to construct a Lwt_stream on top of it.

This might increase performances as well.

This was successfully tested against a small application that uses these APIs: https://github.com/Julow/ocsigen-tictactoe/pull/1

Some work remains to be done:

  • [x] API to unregister callbacks. It was common to cancel a listening loop on a channel using Lwt.cancel or Lwt.pick.
  • [x] Simplify the implementation of Eliom_bus. For example, the callback list could possibly be removed and implemented directly against Eliom_comet.register. This change also opens the door for performance improvements and code simplifications in Eliom_comet.
  • [ ] Investigate the lack of Eliom_bus.original_stream. A comment in Eliom_comet says that messages start receiving only after the load phase, which makes it seems like it is exactly equal to Eliom_bus.stream. It seems that the new API have the same behavior during the load phase and will not lose more messages than the old one when registering callbacks outside of the load phase. This remains to be checked.

Julow avatar Jul 18 '25 13:07 Julow