Skip to content

RFC: Future Combinators (CompioFuture) #603

@George-Miao

Description

@George-Miao

Introduce experimental CompioFuture, which extends IntoFuture and adds some extra combinators. At its core, is a trait that looks like:

pub trait CompioFuture: IntoFuture {
    // combinator functions
}

with default implementation:

impl<F: IntoFuture> CompioFuture for F {}

And compio functions will return impl CompioFuture instead of anonymous futures generated by async. This gives the users the ability to furthur customize the not-yet-fired future in a builder manner, and call await on it after configuration:

let token = CancelToken::new();
let personality = /* */;
file.read(buf).with_cancel(&token).with_personality(personality).await;

and this will not constitute a breaking change, as CompioFuture extends Future (via IntoFuture), and all current use cases should be a subset of what CompioFuture can do.

In combination with try_as_dyn, it's possible to write specialized implementation (especially for user-initiated cancellation, which will be in another RPC based on this).

Metadata

Metadata

Assignees

Labels

RFCRequest for Comment, proposals for features or changesenhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions