gefer

1.0.1 • Public • Published

Gefer

Deferred promises and generators.

Why deferred promises and generators?

Don't. This is bad practice. If at all possible, you should produce promises and generators with well-defined scopes, and no side effects. However, if you find yourself in a bind with no other options, at least keep it clean.

Usage:

Deferred Promise

const { defer } = require('gefer')
 
const deferred = defer()
 
deferred.promise.then(console.log, console.error)
 
deferred.resolve('Hello World')
 
// or deferred.reject(new Error('Foo Bar'))

Deferred Generators

const mySubject = subject()
 
mySubject.next('Hello')
 
const printAll = async () => {
    for await (let v of mySubject()) {
        console.log(v)
    }
}
 
printAll().catch(console.error)
 
mySubject.next('World')
 
// or mySubject.error(new Error('Foo Bar'))

Use a custom promise library

const { Promise } = require('bluebird')
const gefer = require('gefer')
gefer.Promise = Promise

Readme

Keywords

none

Package Sidebar

Install

npm i gefer

Weekly Downloads

41

Version

1.0.1

License

ISC

Unpacked Size

4.51 kB

Total Files

8

Last publish

Collaborators

  • alancnet