Futures-rs: Suggested rename for spawn macros (bikeshedding)

Created on 16 Aug 2018  路  4Comments  路  Source: rust-lang/futures-rs

My suggestion, using familiar shell syntax;
spawn_with_handle! -> bg!
spawn! -> bg_disown!

p.s. If I understand correctly the current spawn! can outlive an async function, so while more performant has the added risk. (Same goes with the other too if dropped i.e. not dealt with later in a await!/join!)

Most helpful comment

These macros don't exist anymore :)

All 4 comments

Probably an appropriate place to include @eddyb's suggestion from reddit:

Maybe the detached spawn! shouldn't be the default, since I don't see it being that useful? If spawn_with_handle! was renamed to spawn! it would match thread::spawn better, and we can use the name spawn_detached! for the other (less common, hopefully) case.

Note that the current spawn_with_handle! returns a JoinHandle which is #[must_use], that should hopefully avoid most cases of accidentally dropping it without awaiting it.

  • The increased length of the name spawn_with_handle! makes it intuitively clear that that macro is more costly than the other one.
  • Spawn::spawn exists and it's nice that the macros and methods have consistent naming. I'm not entirely against renaming these methods, but consistent naming between the macros and the methods is IMO a must.

Maybe the trait itself should have two methods?
Either way, even though there's a cost to the join handle... how useful is spawning a detached future, even? The only things I can think off involve side-effects but don't seem well-behaved.

These macros don't exist anymore :)

Was this page helpful?
0 / 5 - 0 ratings