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

Timers in the thread scheduler #92

Open
KCreate opened this issue Mar 31, 2022 · 0 comments
Open

Timers in the thread scheduler #92

KCreate opened this issue Mar 31, 2022 · 0 comments

Comments

@KCreate
Copy link
Owner

KCreate commented Mar 31, 2022

  • Mechanism to trigger some action at some specified point in time
    • Wake a suspended thread (useful for sleep, timeouts)
    • Create a new fiber from function
  • Timers can be awaited (See Select statement to await multiple values #73):
    • const timeout_timer = Timer.after(1.second)
      const channel = get_some_channel()
      
      select {
        case channel => message {
          print("received: {message}")
        }
      
        case timeout_timer {
          print("timeout!")
        }
      }
  • Timers can be used to implement sleep
    • func sleep(delay) {
        const t = Timer.after(delay)
        await t
      }
  • Timers can be used to call a callback after some time
    • Timer.call_after(1.second) -> {
        print("hello world after 1 second")
      }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant