Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
When you run the following program: ```js import { main } from "effection"; await main(function*() { yield* suspend(); }); ``` You get this error ``` error: Top-level await promise never resolved ``` Because there is literally nothing on the event loop which means that there is nothing that _could_ ever resolve the promise, and yet we should still be suspended. Actually, there _is_ some state in that `main()` registers `SIGINT` handlers, but both Deno and Node say that `SIGINT` doesn't "count" because the state of the art is to call process.exit() on interrupt and shoot the process heart. Effection on the other hand removes the sigint handler, so if that "counted" the `main()` would hold the process open. This just holds the process open by installing a `setInterval` that fires every 2^30 milliseconds (about ten years). It is removed when main is finished. One thing that has occured to me which I'm not sure about is that `run()` will still exhibit the same behavior. In other words: ```js await run(suspend); ``` Will complain that the `run()` promise has not resolved, but that the event loop is exhausted. That feels a bit asymmenric and suprising which is not great. We could make `suspend()` itself hold the event loop with the long interval, although that worries me that every single `suspend()` operation would install a dummy interval. Is it a tough look to have hundreds, or perhaps even thousands of dummy intervals? Another option would be to make any Frame that does not have a parent (aka root frame) of which there is generally only one, hold the event loop, until its destruction. That would allow it to work with a bare `run()`, but not install a `setTimeout` every time a suspend() operation is encountered. The number of dummy intervals would be equal to the number of root frames (most of the time one).
- Loading branch information