Skip to content

Version 0.7.0

Choose a tag to compare

@elinorbgr elinorbgr released this 13 Oct 14:35
· 214 commits to master since this release
v0.7.0
0298796

This new release of calloop brings two major changes: many 'static requirements were lifted from the API, and calloop now provides adapters to integration with the async/await ecosystem.

Lifetimes relaxation

Thanks to @fengalin in PR #20, EventSource objects and their associated callback are no longer required to be 'static, as long as they outlive the EventLoop. It was necessary to adapt a little calloop's API to make this possible, and as a result this is a breaking change.

The most notable change is that LoopHandle::with_source was removed. If you need to access an EventSource after its insertion into the EventLoop, you now instead need to create a Dispatcher and insert it using LoopHandle::register_dispatcher. The Dispatcher holds both an event source and its associated callback, allows you to mutably access the event source, and can be cloned, allowing you to provide it to the event queue and still keep it.

Async/await integration

With this release calloop now provide two tools for integration with the async/await ecosystem: Futures-aware IO and an future executor.

Future-aware IO is provided by the LoopHandle::adapt_io method, which turns an IO object F into an Async<F> adapter, which provides access to futures that resolve when the object is ready for read or write, as well as implementations of the AsyncRead and AsyncWrite traits from the futures crates if the futures-io cargo feature is enabled. This adapter uses the associated EventLoop to awake the futures when IO is ready, allowing the whole construct to run single-threaded.

The future executor is provided as yet another EventSource implementation behind the executor cargo feature, which introduces the std::futures module containing it. The executor has a T type parameter, and can only run futures that resolve to a value of this type. Every time a future spawned in the executor resolves, its value is forwarded to the callback associated to it in the EventLoop. A generic executor for futures that don't return any value can thus be obtained by taking T = ().