Skip to content

timers should be represented by ports #10014

Closed
@metajack

Description

@metajack

The timer code currently has a fundamental flaw, which is that it blocks the task in sleep() and can't be awoken or killed. Instead of exposing sleep, timers should be represented by ports which you recv() on and get a message when the timer fires. Then things making timers could cancel them. Using select on timer and another port could be used to implement timeout messages, etc.

We found this in servo, because calling setTimeout in JavaScript spawns a task that calls sleep and then sends a message. You can't cancel such a timer and exiting before the timer fires is impossible since you can't force kill the task.

cc: @jdm

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-runtimeArea: std's runtime and "pre-main" init for handling backtraces, unwinds, stack overflows

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions