Created
December 1, 2014 07:42
-
-
Save simenbrekken/ba533eb5e2d0f3428dd4 to your computer and use it in GitHub Desktop.
Promise based "taking too long" state switcher.
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 waitFor = lodash.debounce(function(promise) { | |
| /* | |
| You could short circuit this here if you had access to synchonous inspection. | |
| Bluebird: | |
| if (!promise.isPending()) return | |
| Q/when.js: | |
| if (promise.inspect().state !== 'pending') return | |
| */ | |
| this.setState({busy: true}) | |
| return promise.bind(this)..finally(function() { | |
| this.setState({busy: false}) | |
| }) | |
| }, 500) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment