Skip to content

Instantly share code, notes, and snippets.

View acnalesso's full-sized avatar

Antonio C Nalesso Moreira acnalesso

View GitHub Profile
@acnalesso
acnalesso / ordering-a-burger
Created January 28, 2015 17:39
Backburner
var bb = new Backburner(['cook', 'prepare', 'serve']);
var food = { name: "" };
function cookFood(name) {
console.log(name);
food.name = name;
}
function prepareFood() {
console.log('A chef is preparing your food!!!')
@acnalesso
acnalesso / queue.js
Created December 23, 2014 11:46
Queue#invoke
invoke: function(target, method, args, _, _errorRecordedForStack) {
if (args && args.length > 0) {
method.apply(target, args);
} else {
method.call(target);
}
}
@acnalesso
acnalesso / queue.rb
Created December 23, 2014 11:44
queue#invokeWithOnError
invokeWithOnError: function(target, method, args, onError, errorRecordedForStack) {
try {
if (args && args.length > 0) {
method.apply(target, args);
} else {
method.call(target);
}
} catch(error) {
onError(error, errorRecordedForStack);
}
@acnalesso
acnalesso / queue#flush test
Created December 23, 2014 11:30
queue#flush test
test("Queue#flush should be recursive if new items are added", function() {
expect(2);
var bb = new Backburner(['one']);
var count = 0;
bb.run(function(){
function increment() {
if (++count < 3) {
bb.schedule('one', increment);
@acnalesso
acnalesso / flush
Created December 10, 2014 14:02
Queue#flush
flush: {
var queue = this._queue;
var length = queue.length;
if (length == 0) {
return;
}
var globalOptions = this.globalOptions;
var options = this.options;
@acnalesso
acnalesso / flush
Created December 10, 2014 13:34
DeferredActionQueues loop order
Ember.run(function() {
Ember.run.schedule('destroy', function() {
Ember.run.schedule('actions', function() { console.log('actions'); });
Ember.run.schedule('sync', function() { console.log('sync'); });
});
});
// sync
// actions
@acnalesso
acnalesso / example
Last active August 29, 2015 14:11
deferred_queue_actions#flush example
var b = new Backburner(['sync', 'actions', 'destroy'], { ... });
b.run(function() {
b.schedule('actions', function() { console.log('actions'); });
b.schedule('sync', function() {
console.log('flushing sync');
b.schedule('actions', function() { console.log('actions schedduled in sync queue.'); });
});
@acnalesso
acnalesso / flush
Created December 7, 2014 14:33
DeferredActionQueues
flush: function() {
var queues = this.queues;
var queueNames = this.queueNames;
var queueName, queue, queueItems, priorQueueNameIndex;
var queueNameIndex = 0;
var numberOfQueues = queueNames.length;
var options = this.options;
while(queueNameIndex < numberOfQueues) {
queueName = queueNames[queueNameIndex];
@acnalesso
acnalesso / backburner-end
Created December 2, 2014 17:56
backburner end
end: function() {
var options = this.options;
var onEnd = options && options.ondEnd;
var currentInstance = this.currentInstance;
var nextInstance = null;
var finallyAlreadyCalled = false;
try {
currentInstance.flush();
@acnalesso
acnalesso / backburner-run-method
Created December 1, 2014 19:30
Backburner run method
run: function(target, method, /* options, arguments */) {
var onError = getOnError(this.options);
this.begin();
if (!method) {
method = target;
target = null;
}