Extend Node.js requestListeners with deferred promise support
Extends Node.js requestListeners with deferred promise support.
With this library you can turn any listener function that's
function(req, res[, next) into promise capable and still keep it
working the same way.
You can use it with various frameworks and libraries:
It's open source, MIT.
You can install it simply from NPM:
npm install deferred-listener
var deferred_listener = require'deferred-listener';var connect = require'connect';var app = connectusedeferred_listenerconnectlogger'dev'usedeferred_listenerconnectstatic'public'usedeferred_listenernext;// Now, let's try to make a bug and call next againnext;// ...it doesn't work since calling next() only resolves our promise and// it cannot be triggered twice!usedeferred_listenerresend'hello world!\n';listen3000;
requestListener is a function in format
function(request, response[, next]). It's common format for various different Node.js
next is an optional function in format
deferred_listener() returns a wrapper function to
Returned function acts just like the original function but has
additional support for promises. It can still be called with the
callback but instead of calling the original callback directly it will
only reject or resolve single promise and call the original
once. However when called without a
next callback only a promise will