futures-rs icon indicating copy to clipboard operation
futures-rs copied to clipboard

Should `futures::future::abortable` be in `futures::future::FutureExt`?

Open EFanZh opened this issue 4 years ago • 2 comments

Almost all functions in futures::future are future combinators, abortable looks like FutureExt::remote_handle, maybe it belongs to futures::future::FutureExt?

EFanZh avatar Mar 31 '21 08:03 EFanZh

This was discussed in the PR that added abortable: https://github.com/rust-lang/futures-rs/pull/1079#discussion_r201834063

Personal preference but I think this makes more sense as a free function-- you wouldn't chain it like normal combinators since it doesn't return a Future.

taiki-e avatar Mar 31 '21 12:03 taiki-e

What about FutureExt::remote_handle? Like abortable, it also returns a tuple. To compare:

pub fn abortable<Fut>(future: Fut) -> (Abortable<Fut>, AbortHandle)

vs

pub fn remote_handle(self) -> (Remote<Self>, RemoteHandle<Self::Output>)

If remote_handle were implemented as a trait method, it could be like:

pub fn abortable(self) -> (Abortable<Self>, AbortHandle)

I asked this because personally I think functions in FutureExt are easier to discover. It took me some time to find that the abortable function exists.

EFanZh avatar Mar 31 '21 13:03 EFanZh