0.1.1 • Published 10 years ago

@berlysia/remote-switch v0.1.1

Weekly downloads
-
License
MIT
Repository
-
Last release
10 years ago

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

0.1.1

10 years ago

0.1.0

10 years ago

0.0.4

10 years ago

0.0.2

10 years ago

0.0.1

10 years ago