Git Product home page Git Product logo

promiz's Introduction

Promiz.js

Promises/A+ logo A polyfill for ES6-style Promises in 913 bytes (gzip) (v0.3 [Blog Post](http://www.zolmeister.com/2014/01/promiz-micro-promises-in-228-bytes.html)) ~~([How it was built](http://www.zolmeister.com/2013/07/promizjs.html))~~ ![build-status](https://travis-ci.org/Zolmeister/promiz.png?branch=master) ## Install ```bash # Node.js npm install promiz --save

Bower

bower install promiz --save

```html
<!-- Browser -->
<script src='promiz.js'></script>

Promiz - 913 bytes (min + gzip) - as reported by uglify.js

Promiz

HTML5rocks tutorial

Constructor - new Promise(Function<resolve, reject>)

var promise = new Promise(function (resolve, reject) {
  if ('itIsRaining' && Math.random() * 10 === 2) {
    reject(new Error('reason'))
  } else {
    resolve(42)
  }
})

Promise.reject({reason})

promise = Promise.reject(new Error('reason'))

Promise.resolve({value})

promise = Promise.resolve(42)

promise.then({Function}, {Function})

promise = Promise.resolve(42)
promise.then(function (success) {
  return 'Promise resolved to: ' + success
}, function (failure) {
  return 'Promise failed with: ' + failure
})

promise.catch({Function})

promise = Promise.reject(new Error('failure'))
promise.catch(function (failure) {
  return 'Promise failed with: ' + failure
})

Promise.all({iterable})

promise1 = Promise.resolve(1)
promise2 = Promise.resolve(2)
Promise.all([promise1, 123, promise2])
.then(function (promises) {
  promises[0] === 1
  promises[1] === 123
  promises[2] === 2
})

Promise.race({iterable})

promise1 = new Promise()
promise2 = new Promise()

setTimeout(function () {
  promise1.resolve('z')
}, 10)

setTimeout(function () {
  promise2.resolve('l')
}, 100)

Promise.race([promise1, promise2])
.then(function (winner) {
  winner === 'z'
})

Licence: MIT

promiz's People

Contributors

peterdavehello avatar rubenverborgh avatar treri avatar zolmeister 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.