Skip to content

Implement support for event style programming

Deucе requested to merge Deuce/sbbs:echicken-less-grumpy into master

If js.keepGoing 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, events can be added with the following new methods:

  • js.setInterval(callback_function, period_in_ms);
  • js.setTimeout(callback_function, timeout_in_ms);
  • SocketInstance.on('read' | 'write', callback_function);
  • SocketInstance.once('read' | 'write', callback_function);
  • SocketInstance.connect(host, port, 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);
Edited by Deucе

Merge request reports