Skip to content

Make the Reactor public… or split it out? #14

Closed
@Ekleog

Description

@Ekleog

Hello,

First, this looks like an awesome project! Being able to do that much with that little code, and having the ability to seamlessly spawn Send, !Send and blocking tasks looks great.

That being said, I came to smol with, as my main approach, “should a library choose to depend on smol rather than on tokio/async-std” (the best choice IMO being to depend on none, but that may or may not be reasonable depending on the API, too many generic arguments kill everything and taking a trait for every interaction with the outside world can be cumbersome to use… plus no one has written traits that could be used by all libraries and implemented by all executors yet, though I plan on doing that someday in the next twenty years if no one does it before).

And… it looks like (right now) Reactor isn't exposed. Which basically means that a library that chooses to depend on smol won't be usable from other executors without the application spawning a full smol, complete with its three executors. While it probably wouldn't cause any noticeable performance penalty, it still feels unclean.

Hence, I believe it might be helpful to expose the Reactor to the outside world, so that libraries could choose to depend on smol's Reactor and especially the Async struct -- like tokio once did.

Now, there are two ways to go for this: either just make it pub, or make it a completely separate crate. The advantage I would see in making it a completely separate crate would be that then, it becomes easier to port smol to new OSes: it'd just consist in forking the crate, and the user could then simply use the forked reactor, while still using upstream smol. Not sure there's a difference that's not purely theoretical, though the second one might appear a tad bit cleaner.

That'd basically mean splitting smol in two: the Reactor and Async struct, and the executor series and Task struct. Each would then (hopefully) be usable independently. (While still keeping, gated under a feature that's in the default set, the run function using smol's current Reactor for people who just want the easy thing)

What do you think about this idea? Am I missing a reason why that'd not be possible and/or a bad idea?

(also, if you're aiming for feature-parity, I think task_locals are something that can't currently be implemented in a reasonable fashion without support from the executor, so it may make sense to add support for them, but I'm not sure what level of feature-parity you're trying to achieve right now, so won't open an issue straight away -- I can do if you want)

Anyway, thank you for smol, which looks like a really impressive piece of software!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions