Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Single threaded runtime? #43

Open
nastynaz opened this issue May 2, 2024 · 2 comments
Open

Single threaded runtime? #43

nastynaz opened this issue May 2, 2024 · 2 comments

Comments

@nastynaz
Copy link

nastynaz commented May 2, 2024

Is there a way to opt out of the multi-threaded runtime and ensure everything runs on a single thread?

Also, is there a way to sleep?

@nastynaz nastynaz changed the title Single threaded runtime Single threaded runtime? May 2, 2024
@kmf-lab
Copy link

kmf-lab commented Jun 6, 2024

I realize it is a hack but this works great for me. My threads can use normal await without consuming any resources as they "sleep". Once this driver is running in the background everything seems to work well. I also use interrupt that is a key part to make it work.

struct InfiniteSleep;
impl Future for InfiniteSleep {
type Output = ();
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> PollSelf::Output {
cx.waker().wake_by_ref(); //not strictly needed, defencive
trace!("InfiniteSleep Started");
thread::park();
Poll::Pending
}
}
//call this on startup: nuclei::spawn_blocking(|| { nuclei::drive(InfiniteSleep); }).detach();

@nastynaz
Copy link
Author

nastynaz commented Jun 9, 2024

@kmf-lab That is a really neat workaround, thanks for sharing

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

No branches or pull requests

2 participants