pub fn per_connection_init<Config, I, F, R, O, C, Ctx>(
    init: I,
    action: F
) -> impl ResourceConsumer<Config, O, C>where
    Config: ResourceConfig<O, C>,
    Config::Resource: IntoIncoming,
    I: Fn(&Arc<Spirit<O, C>>, &Arc<Config>, &mut Config::Resource, &str) -> Ctx + Send + Sync + 'static,
    F: Fn(&Arc<Spirit<O, C>>, &Arc<Config>, &mut Ctx, <Config::Resource as IntoIncoming>::Connection, &str) -> R + Sync + Send + 'static,
    R: IntoFuture<Item = ()>,
    R::Error: Display,
    R::Future: Sync + Send + 'static,
    O: Send + Sync + 'static,
    C: Send + Sync + 'static,
    Ctx: Send + Sync + 'static,
Expand description

Creates a ResourceConsumer that takes a listener and runs the provided closure on each accepted connection.

This accepts two closures. The first one is run once per each resource to initialize a context for that resource.

Then, whenever a connection is accepted on the resource, the second closure is run (with the connection, the configuration and the context created by the init). The returned future is spawned and becomes an independent task (therefore the connections can be handled by multiple threads if they are available).

The resource accepted by this consumer must implement the IntoIncoming trait (that abstracts over listeners that can accept connections).

Note that an error returned from the incoming stream terminates the resource. Also, the number of accepted connections is unlimited. You probably don’t want that. You can use the WithListenLimits wrapper to get both error handling and limit of parallel connections.

There’s also a simplified per_connection.