Skip to content

Conversation

@pchickey
Copy link
Contributor

Instead of asking the user to thread a Reactor through their program, keep a singleton that is accessible via Reactor::current(). This accessor will panic when called outside of a runtime::block_on, which is a possible footgun that I don't think will be common in practice.

wstd::runtime now contains a thread_local! { pub(crate) static REACTOR: RefCell<Option<Reactor>> }. runtime::block_on populates the RefCell and clears it after the future completes, so it no longer takes a FnOnce(Reactor) -> Fut but just a plain Future argument. Reactor::current returns a clone (cheap, because Rc) of the reactor in the cell.

Eliminating the &'a Reactor from a bunch of structs, in favor of calling Reactor::current() at each use site, means we could eliminate the lifetime parameter from many of the structs.

@pchickey pchickey merged commit fabf596 into main Nov 19, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants