Skip to content

Getting Rid of 'static #3

@anlumo

Description

@anlumo

Hi,

Right now the signature for the future is

pub fn future<TFn, TOutput>(&self, job: TFn) -> impl Future<Output=Result<TOutput, oneshot::Canceled>>+Send
    where   TFn:        'static+Send+for<'a> FnOnce(&'a mut T) -> BoxFuture<'a, TOutput>,
            TOutput:    'static+Send;

However, it should be possible to have this instead:

pub fn future<'a, TFn, TOutput>(&'a self, job: TFn) -> impl 'a + Future<Output=Result<TOutput, oneshot::Canceled>>+Send
    where   TFn:        'a+Send+FnOnce(&'a mut T) -> BoxFuture<'a, TOutput>,
            TOutput:    'a+Send;

because using my_desync.future(…).await makes sure that the Desync stays alive until the passed closure is dropped (either because it was run or because it was canceled).

This would allow using local variables inside the closure passed to the future without capturing them.

Now, I've looked into the desync code and I can see how that's hard to implement, but I created this issue to point out that this would be nice to have in the future (no pun intended).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions