Skip to content

ES6-compatible promise library. Promise/A+ implementation.

Notifications You must be signed in to change notification settings

kissyteam/promise

Folders and files

NameName
Last commit message
Last commit date

Latest commit

author
jianping.xwh
Apr 10, 2015
bea8ed0 · Apr 10, 2015

History

14 Commits
Feb 5, 2015
Apr 10, 2015
Dec 29, 2014
Dec 29, 2014
Sep 16, 2014
Dec 29, 2014
Dec 29, 2014
Dec 29, 2014
Sep 16, 2014
Dec 29, 2014
Sep 16, 2014
Dec 29, 2014
Dec 29, 2014
Dec 29, 2014
Feb 5, 2015
Dec 29, 2014
Feb 5, 2015

Repository files navigation

promise


ES6-compatible promise library. Promise/A+ implementation.

promise SPM version NPM downloads Build Status Coverage Status Dependency Status Bower version node version Sauce Test Status

Sauce Test Status

example

nodejs

var Promise = require('modulex-promise');
readFilePromisified('config.json')
.then(function (text) { // (A)
    var obj = JSON.parse(text);
    console.log(JSON.stringify(obj, null, 4));
})
.catch(function (reason) { // (B)
    // File read error or JSON SyntaxError
    console.error('An error occurred', reason);
});

standalone

<script src="build/promise-standalone-debug.js"></script>
<script>
    (function (Promise) {
        function httpGet(url) {
            return new Promise(
                function (resolve, reject) {
                    var request = new XMLHttpRequest();
                    request.onreadystatechange = function () {
                        if (this.status === 200) {
                            // Success
                            resolve(this.response);
                        } else {
                            // Something went wrong (404 etc.)
                            reject(new Error(this.statusText));
                        }
                    }
                    request.onerror = function () {
                        reject(new Error(
                            'XMLHttpRequest Error: '+this.statusText));
                    };
                    request.open('GET', url);
                    request.send();
                });
        }
        httpGet('http://example.com/file.txt')
        .then(
            function (value) {
                console.log('Contents: ' + value);
            },
            function (reason) {
                console.error('Something went wrong', reason);
            });
    })(XPromise);
</script>

About

ES6-compatible promise library. Promise/A+ implementation.

Resources

Stars

Watchers

Forks

Packages

No packages published