diff options
author | Holden Rohrer <hr@hrhr.dev> | 2020-01-19 20:35:01 -0500 |
---|---|---|
committer | Holden Rohrer <hr@hrhr.dev> | 2020-01-19 20:35:51 -0500 |
commit | 34c860ef99fa155591a657512985553ac3a599fd (patch) | |
tree | 84defa9ed5d72ea69bbd7a761a95e385ca214820 | |
parent | 920a59aa22f0a2dcb3cc9cd00a54e977904cdcf4 (diff) |
added wrapper for socket.js writes
-rw-r--r-- | examples/jarvis.js | 2 | ||||
-rw-r--r-- | utils/writewrap.js | 12 |
2 files changed, 14 insertions, 0 deletions
diff --git a/examples/jarvis.js b/examples/jarvis.js index 8abd9c9..9b692e2 100644 --- a/examples/jarvis.js +++ b/examples/jarvis.js @@ -10,6 +10,7 @@ const sched = require('../tools/schedule'); const ri = require('../utils/rectintersect'); const id = require('../utils/ident'); const maketiles = require('../utils/maketiles'); +const wwrap = require('../utils/writewrap'); //// The queue of all writes to be sent to the server @ 200chars/1000ms var writes = new sched.Queue(1000, 200, (elems) => main.write(elems)); @@ -17,6 +18,7 @@ var main = new Socket(); // See ident.js for further documentation, but this basically sets up init functions id(main, initOnce, init, deinit); +writeListen = new wwrap(main); var sender; function init(send){ diff --git a/utils/writewrap.js b/utils/writewrap.js new file mode 100644 index 0000000..96f1ad1 --- /dev/null +++ b/utils/writewrap.js @@ -0,0 +1,12 @@ +// An EventEmitter wrapper for socket.js writes +const EventEmitter = require('events'); + +class wwrap extends EventEmitter{ + constructor(socket){ + super(); + socket.on('write', (acc) => { // Assumed that none are rejected because I've never seen it + for (w of acc) this.emit(w); + }); + } +} +module.exports = wwrap; |