javascript - Using Promises with EventEmitters -


so if have server in node.js, know can have like:

server.on('request', function() {     console.log('received request'); }); 

but want same thing using promises. imported q , did:

q.nfcall(server.on('request')).then(function() {     console.log('received request'); }); 

but says "typeerror: listener must function." how do this? thanks!

you need pass function q.nfcall, not result of calling .on(). q supply callback argument call. use

q.nfcall(server.on, 'request').then(…) // or rather, since wouldn't context right: q.nbind(server.on, server)('request').then(…) q.ninvoke(server, 'on', 'request').then(…) 

however, doesn't seem idea, request event fires multiple times promise can resolved once (it represents single value). might want frp instead.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -