fastly / js-compute-runtime

JavaScript SDK and runtime for building Fastly Compute applications
https://developer.fastly.com/learning/compute/javascript/
Apache License 2.0
193 stars 26 forks source link

Starlingmonkey timers #798

Closed guybedford closed 1 month ago

guybedford commented 1 month ago

This integrates Fastly support for timers on top of the new deadline() hook on AsyncTask for StarlingMonkey, which is supported by StarlingMonkey timers.

Timers are represented by a handle that is never used in Fastly's host call model. When encountering a timer in the select host hook we check its deadline and progress it if it is ready. We also bound the select call timeout now by the least deadline when timer tasks are present, as we previously implemented.

This architecture also exposes an implementation gap in that setting timers when no other async tasks were pending would never resolve. Without any other primitives to work with a busy loop is implemented in this case to properly support real timeouts and a new test is added. Alternatively, we could throw an error here but I strongly believe we should focus on supporting the code our users write instead of throwing for standard JS patterns.