diff options
author | Holden Rohrer <hr@hrhr.dev> | 2020-07-16 22:23:36 -0400 |
---|---|---|
committer | Holden Rohrer <hr@hrhr.dev> | 2020-07-16 22:26:22 -0400 |
commit | bd53f96d74eed3b4e5b6199edc670d5316c41f24 (patch) | |
tree | 8fe7b9777a91c71bc1de68ea6af429372c2946c9 /examples | |
parent | 6c2e17ac7f2db4d128517ad1854c72e0fdd354ef (diff) |
removed wwrap with less listen-leaky solution
Diffstat (limited to 'examples')
-rw-r--r-- | examples/nword.js | 17 |
1 files changed, 12 insertions, 5 deletions
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; |