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 Passing in anything other than a function will throw |
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 |
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 |
- Source:
- See: