pro

promise4solo

provide a wrap function for promise solo

Showing:

Popularity

Downloads/wk

7

GitHub Stars

0

Maintenance

Last Commit

5yrs ago

Contributors

0

Package

Dependencies

0

Size (min+gzip)

0.3KB

License

ISC

Type Definitions

Tree-Shakeable

No?

Categories

Readme

promise4solo

NPM Build Status Test Coverage Code Climate Issue Count

Installation

$ npm install --save promise4solo

Example

var solo = require('promise4solo')();
var now = function () {
  this.start = this.start || Date.now();
  return Date.now() - this.start;
};

var singAsync = function (ms) {
  var self = this;
  var ts = now();
  if (!ms) {
    throw new Error(ts + self.name + ' oops');
  }
  console.log(ts + self.name + ' begin sing ' + ms);
  return new Promise(function (resolve) {
    setTimeout(function () {
      var end = now();
      console.log(end + self.name + ' end sing ' + ms);
      resolve(end);
    }, ms);
  });
};

var who = {
  name: ' joey'
};

var singSolo = solo(singAsync, who);
var saySolo = solo(function (msg) {
  console.log(now() + this.name + ' say ' + msg);
}, who);

singSolo(1000);
saySolo('hi');
singSolo().catch(function (err) {
  console.log(err.message);
});
singSolo(100).then(function (end) {
  console.log(end + ' done');
});
console.log(now() + ' start');

// Output:
// 0 start
// 3 joey begin sing 1000
// 1011 joey end sing 1000
// 1011 joey say hi
// 1011 joey oops
// 1012 joey begin sing 100
// 1118 joey end sing 100
// 1118 done

API

Return a solo wrap function, and the wrap function will return promise and guarantee one async function be run for order async flow.

solo(func[, thisArg])

var funcAsync = function(val){
  return new Promise(function(resolve){
    //...
    resolve(val);
  });
}

var funcSolo = solo(funcAsync);
funcSolo(true).then(function (val) {

});

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100