Giter Site home page Giter Site logo

el-promise's Introduction

El Promise

Simple Promise library that follows Promises/A+ specification.

Installation

You can install el-promise using npm.

$ npm install --save el-promise

For browser you have to use a module bundler like Webpack or Browserify or you can insert a script tag in you html like this:

<script src="/node_modules/el-promise/build/promise.min.js"></script>

that defines global Promise variable.

In NodeJS you can just require it:

const Promise = require('el-promise');

Usage

The library follows the specs 100% except that there is also a Promise#finally method:

spinner.show();
  
fetchData()
  .then((data) => {
    // do something with data
  })
  .catch((err) => {
    // handle error somehow
  })
  .finally(() => {
    // here you have no arguments
    spinner.hide();
    // the value or the error from the previous promises stands
  });

The method takes a function as an argument that takes 0 arguments. If the function throws an error or returns a rejected promise the returned promise will be rejected with the error. Otherwise the function returns a promise resolved with the previous resolved value or rejected with the previous rejected error. Also if the function returns a promise it will be first resolved but the resulting promise will be resolved with the previous value.

And there is also an abstract Promise#abort method (that may be used by other libraries or you).

For more convenience there are two functions (Promise.onError and Promise.onUnhandledRejection) that are called on any rejection in promise and on an unhandled rejection respectively (with the error argument). If the property (Promise.onError or Promise.onUnhandledRejection) is not a function nothing happens.

el-promise's People

Contributors

droooney avatar jsdelivrbot avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.