Add loopUntilNoMoreEvents() API to wait for arbitrary code.#53
Add loopUntilNoMoreEvents() API to wait for arbitrary code.#53achimnol wants to merge 1 commit intoabbr:masterfrom
Conversation
|
Can you give a use case where the new api is needed? I don't see adding a predicate as inconvenient even when result of async call is not a concern but only the timing matters. |
|
This is required to synchronously execute arbitrary user-input codes, using Of course, this is very "dangerous" for normal node users and I even won't recommend to use this except for very specific use cases. In my case, the node process does not manage any kind of multiplexing at all because there is another separate server daemon that multiplexes multiple clients, detects timeouts, and cleans up no-longer-used or crashed node processes. Each node process is volatile and used only to execute the user code synchronously before returning the results via network. Normally we can just spawn a node process on every user request and wait until it terminates, but we want to keep the context across multiple user code execution requests within a limited time span (e.g., reuse a variable defined by previous code execution requests). This led me to write a kind of "generic barrier" API in this PR. A caveat when using this API is that you need to disable all other pending callbacks to prevent indefinite blocking, socket listeners and timers for example, using |
|
Renamed the new API to loopUntilNoMoreEvents, and rebased the history. |
* Existing APIs rely on explicit callback argument or predicate. This API does not require such prior information, just like how the node.js main loop continues or terminates. * To use this API to block for a specific region of code, you should take care of other existing callbacks using unref() and ref() methods to prevent them from making loopUntilNoMoreEvents() to block "longer" than you want.
This API does not require such prior information, just like
how the nodejs main loop continues or terminates.
take care of other existing callbacks using unref() and ref() methods
to prevent them from making loopUntilNoEvents() to block "longer"
than you want.