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!)
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? Ifspawn_with_handle!was renamed tospawn!it would matchthread::spawnbetter, and we can use the namespawn_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.
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 :)
Most helpful comment
These macros don't exist anymore :)