Skip to content

Conversation

Genaro-Chris
Copy link

No description provided.

@cfsamson
Copy link
Collaborator

cfsamson commented Aug 27, 2025

This is a cool experiment. One challenge I see is that you sleep by actually putting the main thread to sleep, so that means that nothing can be done while a task is sleeping. Am I correct?

The challenge here would be to implement a sleep that doesn't put the main thread to sleep. For example the run function could check a list of timers and see if any has expired, and if so, changing the corresponding tasks state to Ready so that it's scheduled next.

Or you could introduce a new state for the tasks, for example Pending so if all tasks are either available or pending, you can put the main thread to sleep in the run function but use a deadline that equals the time until the earliest timer expires (so that when the run functin continues it will find at least one expired timer in the timer list).

@Genaro-Chris
Copy link
Author

Yeah, you're right but I chose this method because it was the most naive or toy implementation I could think of. I can't really implement it efficiently right now for some reasons

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants