From bd53f96d74eed3b4e5b6199edc670d5316c41f24 Mon Sep 17 00:00:00 2001 From: Holden Rohrer Date: Thu, 16 Jul 2020 22:23:36 -0400 Subject: removed wwrap with less listen-leaky solution --- examples/nword.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'examples') diff --git a/examples/nword.js b/examples/nword.js index 8fe8f5e..2a4e2ce 100644 --- a/examples/nword.js +++ b/examples/nword.js @@ -6,25 +6,32 @@ const Search = require('../tools/search'); const Queue = require('../tools/queue'); const maketiles = require('../utils/maketiles'); const vec = require('../utils/vec'); -const wwrap = require('../utils/writewrap'); const id = require('../utils/ident'); var main = new Socket(); -wwrap.call(main); id.call(main); var search = new Search(); var ids = []; var idcall = []; -var wq = new Queue(1000, 200, (w,max) =>{ +var writeids = {}; +var wq = new Queue(1000, 200, (w,max)=>{ let globid = main.write(w); let id; while (id = ids.shift()) { if (id > max) break; - let run = idcall.shift(); - main.on(globid, ()=>{run();main.off(this)}); + if (writeids[globid]) writeids[globid].push(idcall.shift()); + else writeids[globid] = []; } }); +main.on('write', (acc)=>{ + for (let id in writeids) + if (acc.indexOf(id) > -1){ + for (let it of writeids[id]) + writeids[id](); + delete writeids[id]; + } +}); main.on('init',(send)=>{ main.sender = send; -- cgit