1.0.1 • Published 5 years ago

gefer v1.0.1

Weekly downloads
1
License
ISC
Repository
-
Last release
5 years ago

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