-
-
Save bjouhier/7803022 to your computer and use it in GitHub Desktop.
This file contains 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
//fibers | |
function markComplete(postedItems, completionCallback) { | |
var errors = []; | |
var getItemToUpdate = function(item) { | |
var fiber = Fiber.current; | |
process.nextTick(function() { | |
client.queryEntity('tasks', 'partition1', item, function(err, task) { | |
fiber.run(task); | |
}); | |
}); | |
return Fiber.yield(); | |
}; | |
Fiber(function() { | |
postedItems.forEach(function(item) { | |
task = getItemToUpdate(item); | |
console.log(task); | |
}); | |
completionCallback(undefined); | |
}).run(); | |
} |
Aaah, i saw I could pass to run but didn't realize I can return the yield and it would flow through. OK on the try/catch.
Thanks!
Glenn
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can pass task directly from
fiber.run
toFiber.yield
. So you don't need an extra variable to pass the result.You could also improve by adding a
try/catch
and usingfiber.throwInto
to propagate it.See https://github.com/Sage/streamlinejs/blob/master/lib/fibers/runtime.js#L114-151 for a complete example