Skip to content

argo-rest/any-promise

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 

Repository files navigation

AnyPromise

AnyPromise is an implementation-agnostic JavaScript interface for Promises, based on the ES6 Promise specification.

Libraries requiring Promises can depend on the interface while letting the caller provide the implementation. That way, a library doesn't have to explicitly depend on a given Promise library; it merely depends on the abstract interface.

Example

/* == library.js == */

export function timeoutPromise(Promise, delay) {
  return Promise((resolve, reject) => {
    setTimeout(resolve, delay);
  });
};


/* == consumer.js == */
import {timeoutPromise} from 'library';
import {Promise} from 'any-promise-es6';
// or: import {Promise} from 'any-promise-rsvp';

timeoutPromise(Promise, 1000).then(() => {
  console.log("done waiting 1 second!");
});

timeoutPromise provides an abstract functionality that depends on a Promise interface, but not a specific implementation; the implementation is provided by the caller.

Interface

TODO: describe the interface

Adapters

Adapters are thin wrapper libraries that implement the AnyPromise interface on top of existing Promise libraries:

Known uses

See also

About

Implementation-agnostic JavaScript interface for Promises

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published