2.0.1 • Published 7 years ago

co-agent v2.0.1

Weekly downloads
2
License
MIT
Repository
github
Last release
7 years ago

co-agent

in co warp deal with asynchronous concurrency

Installation

$ npm install co-agent

Usage

reference module:

const CoAgent = require('co-agent');

parameters configure and generating instance:

const coagent = new CoAgent({
    pool: 20,
    safe: true,
    timeout: 5000
});

use instance wrap generator function or other iterator object:

// wrap can use genrator , genrator function and others can change to ierator
coagent.wrap(function* () {
    for (var i = 0; i < 100; i++) {
        // aysnc can use pormise and genrator
        yield aysnc();
    }
}).then(function(data){ 
    //data is an Array of length 100 
 });

coagent.on('resolved',function(data){
    var promise = data.promise;
     var result = data.result;
     //promise.label index
})
coagent.on('resolved',function(data){
    var promise = data.promise;
     var error = data.error;
     //promise.label index
})

coagent.wrap return a promise and each iterator next return is considered an item of an array;

Options

pool: concurrency exec max length;

safe: false one async exec error return promise rejected, true just this return data is null;

timeout: every async exec timeout setting

License

MIT

2.0.1

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago

0.0.0

10 years ago