Skip to content

Instantly share code, notes, and snippets.

@matehat
Created March 24, 2010 18:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save matehat/342570 to your computer and use it in GitHub Desktop.
Save matehat/342570 to your computer and use it in GitHub Desktop.
asyncFunction: (x, y, z) ~>
yield
readFirstFile: (dir, ~, error) ~>
[err, files]: fs.readdir dir, ~
return error(err) if err
[err, out]: fs.readFile files[o], ~
return error(err) if err
yield content
content: fs.readFirstFile dir, ~, (err) -> sys.puts err
cacheData: (data) ->
[code, message]: backend.cache data, ~
log(message) if code is 'error'
map: (list) ~>
res: []
list.forEach (o) ->
res.push(if callback_given? then yield o else o)
list
(function(){
var asyncFunction, cacheData, map, readFirstFile;
asyncFunction = function asyncFunction(x, y, z, __callback) {
return __callback();
};
readFirstFile = function readFirstFile(dir, __callback, error) {
return fs.readdir(dir, (function(__this) {
var __func = function(err, files) {
if (err) {
return error(err);
}
return fs.readFile(files[0], (function(__this) {
var __func = function(err, out) {
if (err) {
return error(err);
}
return __callback(out);
};
return (function() {
return __func.apply(__this, arguments);
});
})(this));
};
return (function() {
return __func.apply(__this, arguments);
});
})(this));
};
readFirstFile(dir, ((function(__this) {
var __func = function(content) { };
return (function() {
return __func.apply(__this, arguments);
});
})(this)), function(err) {
return sys.puts(err);
});
cacheData = function cacheData(data) {
return backend.cache(data, (function(__this) {
var __func = function(code, message) {
if (code === 'error') {
return log(message);
}
};
return (function() {
return __func.apply(__this, arguments);
});
})(this));
};
map = function map(list, __callback) {
var res;
res = [];
list.forEach(function(o) {
if ((typeof __callback !== "undefined" && __callback !== null)) {
return res.push(__callback(o));
} else {
return res.push(o);
}
});
return list;
};
})();
asyncFunction: (x, y, z, __callback) ->
__callback()
readFirstFile: (dir, __callback, error) ->
return fs.readdir dir, (err, files) =>
return error(err) if err
return fs.readFile files[0], (err, out) =>
return error(err) if err
__callback(out)
readFirstFile(dir, ((content) =>), (err) -> sys.puts err)
cacheData: (data) ->
return backend.cache data, (code, message) =>
log(message) if code is 'error'
map: (list, __callback) ->
res: []
list.forEach (o) ->
if __callback? then res.push(__callback(o)) else res.push(o)
list
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment