Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

areq

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

areq - npm Package Compare versions

Comparing version 0.0.9 to 0.1.0

2

package.json
{
"name": "areq",
"version": "0.0.9",
"version": "0.1.0",
"description": "A timeout controller for asynchronous requests with defer.",

@@ -5,0 +5,0 @@ "main": "index.js",

# areq
A timeout controller for asynchronous requests with defer.
[![NPM](https://nodei.co/npm/areq.png?downloads=true)](https://nodei.co/npm/areq/)
[![Travis branch](https://img.shields.io/travis/zigbeer/areq/master.svg?maxAge=2592000)](https://travis-ci.org/zigbeer/areq)

@@ -17,3 +15,2 @@ [![npm](https://img.shields.io/npm/v/areq.svg?maxAge=2592000)](https://www.npmjs.com/package/areq)

4. [APIs](#APIs)
6. [Table of Identifiers](#Identifiers)

@@ -85,8 +82,8 @@ <br />

* emitter (*EventEmitter*): The emitter that emits the events for your listening to resolve the asynchronous responses.
* areqTimeout (*Number*): The default timeout in milliseconds. If elapsed time from the moment of a request sending out has reached this setting, the request will be rejected with a timeout error. If it is not given, a value of 30000 ms will be used as the default.
1. `emitter` (*EventEmitter*): The emitter that emits the events for your listening to resolve the asynchronous responses.
2. `areqTimeout` (*Number*, optional): The default timeout in milliseconds. If elapsed time from the moment of a request sending out has reached this setting, the request will be rejected with a timeout error. If it is not given, a value of 30000 ms will be used as the default.
**Returns:**
* (_Object_) Returns an instance of Areq class.
* (_Object_): Returns an instance of Areq class.

@@ -101,5 +98,4 @@ **Example**

```
********************************************
<br />
<a name="API_register"></a>

@@ -111,6 +107,8 @@ ### register(evt, deferred, listener[, time])

* evt (*String*): The unique event according to the specific response.
* deferred (*Object*): The defer object used in your method.
* listener (*Function*): The event listener. With `areq`, now you should use `areq.resolve(evt, value)` and `areq.reject(evt, err)` instead of using `deferred.resolve(value)` and `deferred.reject(err)`. `areq.resolve()` and `areq.reject()` will take care of the listener deregistering and timeout cleaning for you.
1. `evt` (*String*): The unique event according to the specific response.
2. `deferred` (*Object*): The defer object used in your method.
3. `listener` (*Function*): The event listener. With `areq`, now you should use `areq.resolve(evt, value)` and `areq.reject(evt, err)` instead of using `deferred.resolve(value)` and `deferred.reject(err)`. `areq.resolve()` and `areq.reject()` will take care of the listener deregistering and timeout cleaning for you.
4. `time` (*Number*, optional): Register this areq with a timeout in milliseconds. A default value of 30000 will be used if not given.
**Returns:**

@@ -124,6 +122,7 @@

var myAreqMethod = function () {
var deferred = Q.defer();
var transId = my_nwk_controller.nextTransId();
var eventToListen = 'AF:incomingMsg:' + transId;
// event to listner maybe like this: AF:incomingMsg:172, where 172 is a unique transection id
var deferred = Q.defer(),
transId = my_nwk_controller.nextTransId(),
eventToListen = 'AF:incomingMsg:' + transId;
// event to listner maybe like this: AF:incomingMsg:172,
// where 172 is a unique transection id

@@ -135,3 +134,4 @@ areq.register(eventToListen, deferred, function (result) {

areq.resolve(eventToListen, result);
}, 10000); // if this reponse doesn't come back wihtin 20 secs, your myAreqMethod() will be rejected with a timeout error
}, 10000); // if this reponse doesn't come back wihtin 10 secs,
// your myAreqMethod() will be rejected with a timeout error

@@ -158,5 +158,4 @@ return deferred.promise.nodeify(callback);

```
********************************************
<br />
<a name="API_resolve"></a>

@@ -168,4 +167,4 @@ ### resolve(evt, value)

* evt (*String*): The unique event according to the specific response.
* value (*Depends*): The value you'd like to resolve.
1. `evt` (*String*): The unique event according to the specific response.
2. `value` (*Depends*): The value to be resolved.

@@ -181,5 +180,5 @@ **Returns:**

var myAreqMethod = function () {
var deferred = Q.defer();
var transId = my_nwk_controller.nextTransId();
var eventToListen = 'ZDO:incomingMsg:' + transId;
var deferred = Q.defer(),
transId = my_nwk_controller.nextTransId(),
eventToListen = 'ZDO:incomingMsg:' + transId;

@@ -191,3 +190,4 @@ areq.register(eventToListen, deferred, function (rsp) {

areq.resolve(eventToListen, rsp);
}); // if this reponse doesn't come back wihtin default 30 secs, myAreqMethod() will be rejected with a timeout error
}); // if this reponse doesn't come back wihtin default 30 secs,
// myAreqMethod() will be rejected with a timeout error

@@ -205,5 +205,4 @@ return deferred.promise.nodeify(callback);

```
********************************************
<br />
<a name="API_reject"></a>

@@ -215,4 +214,4 @@ ### reject(evt, err)

* evt (*String*): The unique event according to the specific response.
* err (*Error*): The reason why you reject this response.
1. `evt` (*String*): The unique event according to the specific response.
2. `err` (*Error*): The reason why you reject this response.

@@ -223,10 +222,8 @@ **Returns:**

**Example**
See the exmaple given with [resolve()](#API_resolve_example) method.
********************************************
<br />
<a name="API_getRecord"></a>

@@ -238,9 +235,8 @@ ### getRecord(evt)

* evt (*String*): The unique event according to the specific response.
1. `evt` (*String*): The unique event according to the specific response.
**Returns:**
* (_Object_) The record in the registry.
* (_Object_): The record in the registry.
**Example**

@@ -253,5 +249,4 @@

```
********************************************
<br />
<a name="API_isEventPending"></a>

@@ -263,7 +258,7 @@ ### isEventPending(evt)

* evt (*String*): The unique event according to the specific response.
1. `evt` (*String*): The unique event according to the specific response.
**Returns:**
* (_Boolean_) Return `true` is the given event is pending, otherwise returns `false`.
* (_Boolean_): Return `true` is the given event is pending, otherwise returns `false`.

@@ -277,3 +272,2 @@

```
********************************************
<br />
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc