Skip to content

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

Notifications You must be signed in to change notification settings

kissyteam/promise

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