areq
A timeout controller for asynchronous requests
## Table of Contents
- Overiew
- Installation
- Usage
- APIs
- Table of Identifiers
1. Overview
areq is a timeout controller for asynchronous requests with Promise defers (e.g., Q.defer()).
2. Installation
$ npm install areq --save
3. Usage
areq [TBD].
Here is a quick example.
var Q = require('q'),
Areq = require('areq'),
EventEmitter = require('events');
var myEmitter = Object.create(new EventEmitter()),
areq = new Areq(myEmitter, 6000);
var fooAsyncReq = function (callback) {
var deferred = Q.defer();
areq.register('some_event', deferred, function (result) {
if (result !== 'what_i_want') {
areq.reject('some_event', new Error('Bad response.'));
} else {
areq.resolve('some_event', result);
}
});
return deferred.promise.nodeify(callback);
};
fooAsyncReq(function (err, result) {
if (err)
console.log(err);
else
console.log(result);
});
4. APIs
new Areq(emitter[, areqTimeout])
TBD.
Arguments
- emitter (EventEmitter): TBD
Returns:
- (Object) Returns an instance of Areq class.
Example
register(evt, deferred, listener[, time])
TBD.
Arguments
Returns:
Example
resolve(evt, value)
TBD.
Arguments
Returns:
Example
reject(evt, err)
TBD.
Arguments
Returns:
Example
getRecord(evt)
TBD.
Arguments
Returns:
Example
isEventPending(evt)
TBD.
Arguments
Returns:
Example