Skip to content

Instantly share code, notes, and snippets.

@thgreasi
thgreasi / debouceWithResult.js
Last active August 19, 2018 23:13
[Moved to https://github.com/thgreasi/debounce-with-result.js] An improved version of debounce that returns a Promise and can handle return values. Returns a single Promise for each separate group of debounced invocations.
function debounceWithResult (func, wait, immediate) {
function newDeferred () {
var deferred = {};
deferred.promise = new Promise(function (resolve, reject) {
deferred.resolve = resolve;
deferred.reject = reject;
});
return deferred;
}
<!-- place at ~/.config/sublime-text-3/Packages/User/$any.sublime-snippet -->
<snippet>
<content><![CDATA[
{
\$any: {
\$alias: '${1:this}',
\$expr: {
${1:this}: {
},
},