client: Direct-style API for `Eliom_comet` and `Eliom_bus`
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 usingLwt_streaminternally.Eliom_bus.streamis re-implemented against the register API.Eliom_bus.original_streamis not re-implemented yet. -
Eliom_comet.Channelis an abstract type instead of aLwt_stream.Lwt_streamis 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 aLwt_streamon 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.cancelorLwt.pick. - [x] Simplify the implementation of
Eliom_bus. For example, the callback list could possibly be removed and implemented directly againstEliom_comet.register. This change also opens the door for performance improvements and code simplifications inEliom_comet. - [ ] Investigate the lack of
Eliom_bus.original_stream. A comment inEliom_cometsays that messages start receiving only after the load phase, which makes it seems like it is exactly equal toEliom_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.