Created
December 19, 2014 13:21
-
-
Save briancavalier/f606b6af9b35855c092f to your computer and use it in GitHub Desktop.
A simple test of AbortablePromise. See https://github.com/cujojs/when/pull/415
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var Promise = require('when/lib/Promise'); | |
| var makeAbortablePromise = require('when/lib/makeAbortablePromise'); | |
| var AbortablePromise = makeAbortablePromise(Promise); | |
| var p = new AbortablePromise(function() { | |
| var t = setInterval(function() { | |
| console.log('running'); | |
| }, 100); | |
| return function() { | |
| console.log('aborted'); | |
| clearInterval(t); | |
| return 'Abort result'; | |
| }; | |
| }); | |
| // Ensure that abort is propagated thru the promise graph | |
| p = p.then(); | |
| setTimeout(function() { | |
| var result = p.abort(); | |
| console.log(result); // This will log a promise object | |
| result.then(console.log); // This will log "Abort result" | |
| p.abort(); // Ensure abort can only run once | |
| }, 500); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment