Skip to content

Instantly share code, notes, and snippets.

View Aaronius's full-sized avatar

Aaron Hardy Aaronius

View GitHub Profile
@Aaronius
Aaronius / sequence.js
Last active September 15, 2017 11:54
Promise-based Sequential Queue
// Queues multiple asynchronous processes to run sequentially via promises
// Process can be added to the queue while other processes are running
var Sequence = function() {};
Sequence.prototype.enqueue = function(fn) {
this.tail = this.tail ? this.tail.finally(fn) : fn();
};
// Usage
// From http://stackoverflow.com/questions/13320015/how-to-write-a-debounce-service-in-angularjs
.factory('debounce', function($timeout, $q) {
return function(func, wait, immediate) {
var timeout;
var deferred = $q.defer();
return function() {
var context = this, args = arguments;
var later = function() {
timeout = null;
if(!immediate) {