1.0.2 • Published 4 years ago

@pushstack/promise v1.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
4 years ago

sopromise

A sample implementation of Promises/A+.

Usage

npm i sopromise

Example:

import Promise from 'sopromise';

let p1 = function() {
  return new Promise((resolve, reject) => {
    setTimeout(function() {
      resolve('hello Promise');
    }, 1000);
  });
};

p1()
  .then(
    res => {
      console.log('res: ', res);
    },
    error => {
      console.log('error: ', error);
    }
  )
  .catch(error => {
    console.log('error finally: ', error);
  });
// res:  hello Promise

// with async await
async function asyncTest() {
  let res = await p1();
  console.log('async function result: ', res);
}

asyncTest();
// async function result:  hello Promise

Include Methods

Test

Use promises-aplus-tests to test.

npm run test

Todos

  • implement Promises/A+
  • use rollup to build
  • add methods: resolve, reject, all, race, finally

License

MIT License