Implement support for callback style programming
If js.do_callbacks is set to true, a script will not terminate when it finishes. Instead, it will enter an event loop running installed callbacks when configured events occurs. Currently, callbacks can be added with the following new methods:
- js.setInterval(callback_function, period_in_ms[, thisObj]);
- js.setTimeout(callback_function, timeout_in_ms[, thisObj]);
- SocketInstance.on('read' | 'write', callback_function);
- SocketInstance.once('read' | 'write', callback_function);
- SocketInstance.connect(host, port, callback_function);
- console.on('read', callback_function);
- console.once('read', callback_function);
Aside from Socket.connect(), these functions return a value that can be passed to a matching clear function:
- js.clearInterval(id);
- js.clearTimeout(id);
- SocketInstance.clearOn('read' | 'write', id);
- SocketInstance.clearOnce('read' | 'write', id);
- console.clearOn('read' | 'write', id);
- console.clearOnce('read' | 'write', id);
Additionally, user-defined events are now supported:
- js.addEventListener(eventName, callback)
- js.removeEventListener(id)
- js.dispatchEvent(eventName[, thisObj])
We also get a cool event-based DNS library.
Edited by Deucе
Merge request reports
Activity
added 8 commits
-
daf7e528...d457835c - 7 commits from branch
main:master
- a980e336 - Merge remote-tracking branch 'origin/master' into echicken-less-grumpy
-
daf7e528...d457835c - 7 commits from branch
added 1 commit
- 3631f03d - Use PREFER_POLL to select poll() over select(), not _WIN32
added 1 commit
- f2c0b614 - Initial attempt at console.on() and console.once()
added 1 commit
- 91cf4e45 - Fix console.on() and console.once() for incoming data
added 1 commit
- 4c667b4b - Reset the next event id to zero when events are cleared.
added 1 commit
- aae28968 - Save a reference to js_callback_t when event is created
Please register or sign in to reply