|
2 anni fa | |
---|---|---|
.. | ||
lib | 2 anni fa | |
LICENSE | 2 anni fa | |
README.md | 2 anni fa | |
index.js | 2 anni fa | |
package.json | 2 anni fa |
throw er ==> return cb(er)
// return true if a path is either
// a symlink or a directory.
function isLinkOrDir (path, cb) {
fs.lstat(path, function (er, s) {
if (er) return cb(er)
return cb(null, s.isDirectory() || s.isSymbolicLink())
})
}
var asyncMap = require("slide").asyncMap
function writeFiles (files, what, cb) {
asyncMap(files, function (f, cb) {
fs.writeFile(f, what, cb)
}, cb)
}
writeFiles([my, file, list], "foo", cb)
I still have to provide an array of functions, which is a lot of boilerplate, and a pita if your functions take args like
function (cb) {
blah(a, b, c, cb)
}
Results are discarded, which is a bit lame.
No way to branch.
branching, skipping over falsey arguments
chain([
doThing && [thing, a, b, c]
, isFoo && [doFoo, "foo"]
, subChain && [chain, [one, two]]
], cb)
tracking results: results are stored in an optional array passed as argument, last result is always in results[results.length - 1].
treat chain.first and chain.last as placeholders for the first/last result up until that point.
Delete the number files
var chain = require("slide").chain
function myProgram (cb) {
var res = [], last = chain.last, first = chain.first
chain([
[fs, "readdir", "the-directory"]
, [readFiles, "the-directory", last]
, [sum, last]
, [ping, "POST", "example.com", 80, "/foo", last]
, [fs, "writeFile", "result.txt", last]
, [rmFiles, "./the-directory", first]
], res, cb)
}