Skip to content

Instantly share code, notes, and snippets.

@simenbrekken
Created December 1, 2014 07:42
Show Gist options
  • Select an option

  • Save simenbrekken/ba533eb5e2d0f3428dd4 to your computer and use it in GitHub Desktop.

Select an option

Save simenbrekken/ba533eb5e2d0f3428dd4 to your computer and use it in GitHub Desktop.
Promise based "taking too long" state switcher.
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