This file contains hidden or 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
Imagine that you have lisp envy, but your brain can't quite handle all | |
the parentheses. Here's my idea for more readable s-expressions. | |
When you begin parsing, you start in terminator mode. In terminator | |
mode, an expression is a series of space separated expressions | |
terminated by a newline or semicolon: | |
print "hello" | |
eat "tomatoes" | |
clean "dishes" |
This file contains hidden or 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
/* in this case, there is no explicit wait() function, instead, fiberized functions use the yield keyword */ | |
module.exports = function(generatorFunction) { | |
var iterator; | |
function resume() { | |
iterator.send(arguments); | |
} | |
iterator = generatorFunction(resume); | |
iterator.next(); | |
}; |
This file contains hidden or 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
require('fibers'); | |
module.exports = function(fn) { | |
Fiber(function() { | |
var fiber = Fiber.current; | |
var wait = yield; | |
var resume = function() { | |
fiber.run(arguments); | |
}; | |
fn(resume, wait); |
This file contains hidden or 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
// saves local changes to articles. mergeParentGuid should be null unless we are resolving a merge conflict | |
function editArticle(articleName, content, mergeParentGuid, callback) { | |
flow.exec( | |
function() { | |
// find my current head for this article | |
db.sync.findLastLocal("articleHeads", {name: articleName}, this) | |
},function(err, articleHead) { | |
if (err) throw err |
This file contains hidden or 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
var sys = require('sys'); | |
var flow = require('./flow') | |
// this is a simple async function for adding an amount to a running total | |
var currentSum = 0; | |
function addToSum(amountToAdd, callback) { | |
setTimeout(function() { | |
currentSum += amountToAdd; | |
callback(); | |
}, 100); |
This file contains hidden or 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
var sys = require('sys'); | |
var flow = require('./flow') | |
// this is a simple async function for adding an amount to a running total | |
var currentSum = 0; | |
function addToSum(amountToAdd, callback) { | |
setTimeout(function() { | |
currentSum += amountToAdd; | |
callback(); | |
}, 100); |