PromiseAdapter(create, resolve, reject)

new PromiseAdapter(create, resolve, reject)

Adapter for the primary promise operations.

Provides compatibility with promise libraries that cannot be recognized automatically, via functions that implement the primary operations with promises:

  • construct a new promise with a callback function
  • resolve a promise with some result data
  • reject a promise with a reason

Example

Below is an example of setting up a client-side adapter for AngularJS $q.

const spexLib = require('spex'); // or include client-side spex.js

const adapter = new spexLib.PromiseAdapter(
   cb => $q(cb), // creating a new promise;
   data => $q.when(data), // resolving a promise;
   reason => $q.reject(reason) // rejecting a promise;
   );

const spex = spexLib(adapter);
Parameters:
Name Type Description
create function

A function that takes a callback parameter and returns a new promise object. The callback parameter is expected to be function(resolve, reject).

Passing in anything other than a function will throw Adapter requires a function to create a promise.

resolve function

A function that takes an optional data parameter and resolves a promise with it.

Passing in anything other than a function will throw Adapter requires a function to resolve a promise.

reject function

A function that takes an optional error parameter and rejects a promise with it.

Passing in anything other than a function will throw Adapter requires a function to reject a promise.

Source:
See: