promiz

A proper compact promise (promises/A+ spec compliant) library.

A polyfill for ES6-style Promises in 887 bytes (gzip) (v0.3 Blog Post) (How it was built)

# Node.js
npm install promiz --save
 
# Bower
bower install promiz --save
<!-- Browser -->
<script src='promiz.js'></script>

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

HTML5rocks tutorial

var promise = new Promise(function (resolvereject) {
  if ('itIsRaining' && Math.random() * 10 === 2) {
    reject(new Error('reason'))
  } else {
    resolve(42)
  }
})
promise = Promise.reject(new Error('reason'))
promise = Promise.resolve(42)
promise = Promise.resolve(42)
promise.then(function (success) {
  return 'Promise resolved to: ' + success
}, function (failure) {
  return 'Promise failed with: ' + failure
})
promise = Promise.reject(new Error('failure'))
promise.catch(function (failure) {
  return 'Promise failed with: ' + failure
})
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
})
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'
})