Skip to content

Commit

Permalink
Update README.md - setTimeout()/setInterval() (#643)
Browse files Browse the repository at this point in the history
* Update README.md - setTimeout()/setInterval()

Brings more context about the implementation of setTimeout/setInterval - and why a JS engine cannot provide their implementation.
  • Loading branch information
stroiman authored Jan 14, 2025
1 parent 79f3a7e commit 46d383d
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,11 @@ No. An instance of goja.Runtime can only be used by a single goroutine
at a time. You can create as many instances of Runtime as you like but
it's not possible to pass object values between runtimes.

### Where is setTimeout()?
### Where is setTimeout()/setInterval()?

setTimeout() and setInterval() are common functions to provide concurrent execution in ECMAScript environments, but the two functions are not part of the ECMAScript standard.
Browsers and NodeJS just happen to provide similar, but not identical, functions. The hosting application need to control the environment for concurrent execution, e.g. an event loop, and supply the functionality to script code.

setTimeout() assumes concurrent execution of code which requires an execution
environment, for example an event loop similar to nodejs or a browser.
There is a [separate project](https://github.com/dop251/goja_nodejs) aimed at providing some NodeJS functionality,
and it includes an event loop.

Expand Down

0 comments on commit 46d383d

Please sign in to comment.