@berlysia/remote-switch
remote-switch =====
Last updated 5 years ago by berlysia .
MIT · Original npm · Tarball · package.json
$ cnpm install @berlysia/remote-switch 
SYNC missed versions from official npm registry.

remote-switch

Promise wrapper for remote resolve/reject.

Description

Making 'chain of Promise' but not want to execute immediately,

Requirement

No deps, but Promise required.

Usage

var RemoteSwitch = require('@berlysia/remote-switch');
var rs = new RemoteSwitch;
var log = console.log.bind(console);

rs
.then(function(){return 123})
.then(log)
.then(function(){return 456})
.then(log);
// no output

rs.fire(); // wrapped rs.resolve(), method chainable
// 123
// 456

rs
.then(function(){return 123})
.then(log)
.then(function(){return 456})
.then(log);
// 123
// 456

rs.then(func) is syntax sugar of promise = promise.then(func).

if you want to access last promise, rs.current is what you want.

rs
.then(function(){return 123})
.then(console.log.bind(console))
.then(spy)
.then(assert(!spy.called))
.then(()=>assert(spy.called))
.fire();
// => ok!

Install

npm install @berlysia/remote-switch

Licence

MIT

Author

berlysia

Current Tags

  • 0.1.1                                ...           latest (5 years ago)

4 Versions

  • 0.1.1                                ...           5 years ago
  • 0.1.0                                ...           5 years ago
  • 0.0.4                                ...           5 years ago
  • 0.0.2                                ...           5 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (0)
None
Dev Dependencies (14)
Dependents (1)

Copyright 2014 - 2017 © taobao.org |