A polyfill for ES6-style Promises in 913 bytes (gzip)
JavaScript
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
imgs added promise logo Jan 8, 2014
test Allow promise rejection with another promise, fixes #13 Dec 19, 2015
.gitignore commented code and added bench.js Jul 21, 2013
.travis.yml
Gruntfile.js
LICENSE
README.md
bower.json passes promises-a+ with constructor style Oct 25, 2014
package.json 1.0.5 Dec 19, 2015
promiz.js
promiz.min.js

README.md

Promiz.js

Promises/A+ logo A polyfill for ES6-style Promises in 913 bytes (gzip) (v0.3 Blog Post) (How it was built)
build-status

Install

# Node.js
npm install promiz --save

# Bower
bower install promiz --save
<!-- 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