actix-interop
Allows using async/await syntax to implement actix actors, and provides a convenient way to control access to an actor's state.
# Cargo.toml
[]
= "0.3"
Example
This example shows how you could implement a generic "pipeline adapter"
which allows turning any Sink
/Stream
pair (forming a request/response
pipeline) into an actix Actor.
Responses are matched up with their requests according to the order
in which they were sent (so the first response corresponds to the
first request sent to the Sink
, etc). This requires that our "send"
operations are strictly ordered, and this is difficult to achieve
in actix because async operations are normally allowed to interleave.
Furthermore, although the sends must be atomic, we also want to be
able to have a large number of requests in-flight at any given time,
so the receiving part of the message handler must not require exclusive
access to the actor while it is waiting. As a result, abstractions
like the AtomicResponse
type are too simplistic to help.
To solve this problem, we use the critical_section
function to allow specific parts of our message handler to be atomic.
use VecDeque;
use Pin;
use ;
use *;
use ;
// Define our actor
// Implement a constructor
// Tell actix this is an actor using the default Context type
// Transform actix messages into the pipelines request/response protocol
// Process responses
License
This project is licensed under either of
- Apache License, Version 2.0, (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in actix-interop by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.