| 1 |
{ |
| 2 |
"_id": "slide", |
| 3 |
"_rev": "51-018091b79d4795e248574383e48ac159", |
| 4 |
"name": "slide", |
| 5 |
"description": "A flow control lib small enough to fit on in a slide presentation. Derived live at Oak.JS", |
| 6 |
"dist-tags": { |
| 7 |
"latest": "1.1.6" |
| 8 |
}, |
| 9 |
"versions": { |
| 10 |
"1.0.0": { |
| 11 |
"name": "slide", |
| 12 |
"version": "1.0.0", |
| 13 |
"author": { |
| 14 |
"name": "Isaac Z. Schlueter", |
| 15 |
"email": "[email protected]", |
| 16 |
"url": "http://blog.izs.me/" |
| 17 |
}, |
| 18 |
"description": "A flow control lib small enough to fit on in a slide presentation. Derived live at Oak.JS", |
| 19 |
"directories": { |
| 20 |
"lib": "lib" |
| 21 |
}, |
| 22 |
"_id": "[email protected]", |
| 23 |
"engines": { |
| 24 |
"node": "*" |
| 25 |
}, |
| 26 |
"_nodeSupported": true, |
| 27 |
"_npmVersion": "0.2.7-2", |
| 28 |
"_nodeVersion": "v0.3.1-pre", |
| 29 |
"dist": { |
| 30 |
"tarball": "https://registry.npmjs.org/slide/-/slide-1.0.0.tgz", |
| 31 |
"shasum": "c3842da5e075b83eb68864c3fa64d752121b17f1" |
| 32 |
} |
| 33 |
}, |
| 34 |
"1.0.1": { |
| 35 |
"name": "slide", |
| 36 |
"version": "1.0.1", |
| 37 |
"author": { |
| 38 |
"name": "Isaac Z. Schlueter", |
| 39 |
"email": "[email protected]", |
| 40 |
"url": "http://blog.izs.me/" |
| 41 |
}, |
| 42 |
"contributors": [ |
| 43 |
{ |
| 44 |
"name": "S. Sriram", |
| 45 |
"email": "[email protected]", |
| 46 |
"url": "http://www.565labs.com" |
| 47 |
} |
| 48 |
], |
| 49 |
"description": "A flow control lib small enough to fit on in a slide presentation. Derived live at Oak.JS", |
| 50 |
"directories": { |
| 51 |
"lib": "lib" |
| 52 |
}, |
| 53 |
"_id": "[email protected]", |
| 54 |
"engines": { |
| 55 |
"node": "*" |
| 56 |
}, |
| 57 |
"_engineSupported": true, |
| 58 |
"_npmVersion": "0.2.14-6", |
| 59 |
"_nodeVersion": "v0.3.5-pre", |
| 60 |
"modules": { |
| 61 |
"b/async-map.js": "lib/async-map.js", |
| 62 |
"b/bind-actor.js": "lib/bind-actor.js", |
| 63 |
"b/chain.js": "lib/chain.js" |
| 64 |
}, |
| 65 |
"files": [ |
| 66 |
"" |
| 67 |
], |
| 68 |
"_defaultsLoaded": true, |
| 69 |
"dist": { |
| 70 |
"shasum": "b7d9076eee798237666e66e3f18157532b297f32", |
| 71 |
"tarball": "https://registry.npmjs.org/slide/-/slide-1.0.1.tgz" |
| 72 |
} |
| 73 |
}, |
| 74 |
"1.1.0": { |
| 75 |
"name": "slide", |
| 76 |
"version": "1.1.0", |
| 77 |
"author": { |
| 78 |
"name": "Isaac Z. Schlueter", |
| 79 |
"email": "[email protected]", |
| 80 |
"url": "http://blog.izs.me/" |
| 81 |
}, |
| 82 |
"contributors": [ |
| 83 |
{ |
| 84 |
"name": "S. Sriram", |
| 85 |
"email": "[email protected]", |
| 86 |
"url": "http://www.565labs.com" |
| 87 |
} |
| 88 |
], |
| 89 |
"description": "A flow control lib small enough to fit on in a slide presentation. Derived live at Oak.JS", |
| 90 |
"main": "./lib/slide", |
| 91 |
"_id": "[email protected]", |
| 92 |
"engines": { |
| 93 |
"node": "*" |
| 94 |
}, |
| 95 |
"_engineSupported": true, |
| 96 |
"_npmVersion": "0.2.17", |
| 97 |
"_nodeVersion": "v0.3.8-pre", |
| 98 |
"directories": { |
| 99 |
"lib": "./lib" |
| 100 |
}, |
| 101 |
"files": [ |
| 102 |
"" |
| 103 |
], |
| 104 |
"_defaultsLoaded": true, |
| 105 |
"dist": { |
| 106 |
"shasum": "a9e135aa14bf5bb8b8c9e16c723c7223ac30f717", |
| 107 |
"tarball": "https://registry.npmjs.org/slide/-/slide-1.1.0.tgz" |
| 108 |
} |
| 109 |
}, |
| 110 |
"1.1.1": { |
| 111 |
"name": "slide", |
| 112 |
"version": "1.1.1", |
| 113 |
"author": { |
| 114 |
"name": "Isaac Z. Schlueter", |
| 115 |
"email": "[email protected]", |
| 116 |
"url": "http://blog.izs.me/" |
| 117 |
}, |
| 118 |
"contributors": [ |
| 119 |
{ |
| 120 |
"name": "S. Sriram", |
| 121 |
"email": "[email protected]", |
| 122 |
"url": "http://www.565labs.com" |
| 123 |
} |
| 124 |
], |
| 125 |
"description": "A flow control lib small enough to fit on in a slide presentation. Derived live at Oak.JS", |
| 126 |
"main": "./lib/slide.js", |
| 127 |
"_id": "[email protected]", |
| 128 |
"engines": { |
| 129 |
"node": "*" |
| 130 |
}, |
| 131 |
"_engineSupported": true, |
| 132 |
"_npmVersion": "1.0.0", |
| 133 |
"_nodeVersion": "v0.5.0-pre", |
| 134 |
"directories": { |
| 135 |
"lib": "./lib" |
| 136 |
}, |
| 137 |
"_defaultsLoaded": true, |
| 138 |
"dist": { |
| 139 |
"shasum": "198afd3d6aab806681924a08e49b5758fb1c49b6", |
| 140 |
"tarball": "https://registry.npmjs.org/slide/-/slide-1.1.1.tgz" |
| 141 |
} |
| 142 |
}, |
| 143 |
"1.1.2": { |
| 144 |
"name": "slide", |
| 145 |
"version": "1.1.2", |
| 146 |
"author": { |
| 147 |
"name": "Isaac Z. Schlueter", |
| 148 |
"email": "[email protected]", |
| 149 |
"url": "http://blog.izs.me/" |
| 150 |
}, |
| 151 |
"contributors": [ |
| 152 |
{ |
| 153 |
"name": "S. Sriram", |
| 154 |
"email": "[email protected]", |
| 155 |
"url": "http://www.565labs.com" |
| 156 |
} |
| 157 |
], |
| 158 |
"description": "A flow control lib small enough to fit on in a slide presentation. Derived live at Oak.JS", |
| 159 |
"main": "./lib/slide.js", |
| 160 |
"dependencies": {}, |
| 161 |
"devDependencies": {}, |
| 162 |
"engines": { |
| 163 |
"node": "*" |
| 164 |
}, |
| 165 |
"repository": { |
| 166 |
"type": "git", |
| 167 |
"url": "git://github.com/isaacs/slide-flow-control.git" |
| 168 |
}, |
| 169 |
"_npmJsonOpts": { |
| 170 |
"file": "/Users/isaacs/.npm/slide/1.1.2/package/package.json", |
| 171 |
"wscript": false, |
| 172 |
"contributors": false, |
| 173 |
"serverjs": false |
| 174 |
}, |
| 175 |
"_id": "[email protected]", |
| 176 |
"_engineSupported": true, |
| 177 |
"_npmVersion": "1.0.18", |
| 178 |
"_nodeVersion": "v0.4.10-pre", |
| 179 |
"_defaultsLoaded": true, |
| 180 |
"dist": { |
| 181 |
"shasum": "6339e63a65f1d5f6b0ab9a573a6ca276993aad7d", |
| 182 |
"tarball": "https://registry.npmjs.org/slide/-/slide-1.1.2.tgz" |
| 183 |
}, |
| 184 |
"scripts": {}, |
| 185 |
"directories": {} |
| 186 |
}, |
| 187 |
"1.1.3": { |
| 188 |
"name": "slide", |
| 189 |
"version": "1.1.3", |
| 190 |
"author": { |
| 191 |
"name": "Isaac Z. Schlueter", |
| 192 |
"email": "[email protected]", |
| 193 |
"url": "http://blog.izs.me/" |
| 194 |
}, |
| 195 |
"contributors": [ |
| 196 |
{ |
| 197 |
"name": "S. Sriram", |
| 198 |
"email": "[email protected]", |
| 199 |
"url": "http://www.565labs.com" |
| 200 |
} |
| 201 |
], |
| 202 |
"description": "A flow control lib small enough to fit on in a slide presentation. Derived live at Oak.JS", |
| 203 |
"main": "./lib/slide.js", |
| 204 |
"dependencies": {}, |
| 205 |
"devDependencies": {}, |
| 206 |
"engines": { |
| 207 |
"node": "*" |
| 208 |
}, |
| 209 |
"repository": { |
| 210 |
"type": "git", |
| 211 |
"url": "git://github.com/isaacs/slide-flow-control.git" |
| 212 |
}, |
| 213 |
"_npmJsonOpts": { |
| 214 |
"file": "/Users/isaacs/.npm/slide/1.1.3/package/package.json", |
| 215 |
"wscript": false, |
| 216 |
"contributors": false, |
| 217 |
"serverjs": false |
| 218 |
}, |
| 219 |
"_id": "[email protected]", |
| 220 |
"_engineSupported": true, |
| 221 |
"_npmVersion": "1.0.22", |
| 222 |
"_nodeVersion": "v0.4.10-pre", |
| 223 |
"_defaultsLoaded": true, |
| 224 |
"dist": { |
| 225 |
"shasum": "a16975ba76b766b92f98ef337243336c1fa3238f", |
| 226 |
"tarball": "https://registry.npmjs.org/slide/-/slide-1.1.3.tgz" |
| 227 |
}, |
| 228 |
"scripts": {}, |
| 229 |
"directories": {} |
| 230 |
}, |
| 231 |
"1.1.4": { |
| 232 |
"name": "slide", |
| 233 |
"version": "1.1.4", |
| 234 |
"author": { |
| 235 |
"name": "Isaac Z. Schlueter", |
| 236 |
"email": "[email protected]", |
| 237 |
"url": "http://blog.izs.me/" |
| 238 |
}, |
| 239 |
"contributors": [ |
| 240 |
{ |
| 241 |
"name": "S. Sriram", |
| 242 |
"email": "[email protected]", |
| 243 |
"url": "http://www.565labs.com" |
| 244 |
} |
| 245 |
], |
| 246 |
"description": "A flow control lib small enough to fit on in a slide presentation. Derived live at Oak.JS", |
| 247 |
"main": "./lib/slide.js", |
| 248 |
"dependencies": {}, |
| 249 |
"devDependencies": {}, |
| 250 |
"engines": { |
| 251 |
"node": "*" |
| 252 |
}, |
| 253 |
"repository": { |
| 254 |
"type": "git", |
| 255 |
"url": "git://github.com/isaacs/slide-flow-control.git" |
| 256 |
}, |
| 257 |
"bugs": { |
| 258 |
"url": "https://github.com/isaacs/slide-flow-control/issues" |
| 259 |
}, |
| 260 |
"_id": "[email protected]", |
| 261 |
"dist": { |
| 262 |
"shasum": "2b23f1949b369ed61d22bd6570ff0320302fc8df", |
| 263 |
"tarball": "https://registry.npmjs.org/slide/-/slide-1.1.4.tgz" |
| 264 |
}, |
| 265 |
"_from": ".", |
| 266 |
"_npmVersion": "1.2.18", |
| 267 |
"_npmUser": { |
| 268 |
"name": "isaacs", |
| 269 |
"email": "[email protected]" |
| 270 |
}, |
| 271 |
"maintainers": [ |
| 272 |
{ |
| 273 |
"name": "isaacs", |
| 274 |
"email": "[email protected]" |
| 275 |
} |
| 276 |
], |
| 277 |
"directories": {} |
| 278 |
}, |
| 279 |
"1.1.5": { |
| 280 |
"name": "slide", |
| 281 |
"version": "1.1.5", |
| 282 |
"author": { |
| 283 |
"name": "Isaac Z. Schlueter", |
| 284 |
"email": "[email protected]", |
| 285 |
"url": "http://blog.izs.me/" |
| 286 |
}, |
| 287 |
"contributors": [ |
| 288 |
{ |
| 289 |
"name": "S. Sriram", |
| 290 |
"email": "[email protected]", |
| 291 |
"url": "http://www.565labs.com" |
| 292 |
} |
| 293 |
], |
| 294 |
"description": "A flow control lib small enough to fit on in a slide presentation. Derived live at Oak.JS", |
| 295 |
"main": "./lib/slide.js", |
| 296 |
"dependencies": {}, |
| 297 |
"devDependencies": {}, |
| 298 |
"engines": { |
| 299 |
"node": "*" |
| 300 |
}, |
| 301 |
"repository": { |
| 302 |
"type": "git", |
| 303 |
"url": "git://github.com/isaacs/slide-flow-control.git" |
| 304 |
}, |
| 305 |
"license": "ISC", |
| 306 |
"bugs": { |
| 307 |
"url": "https://github.com/isaacs/slide-flow-control/issues" |
| 308 |
}, |
| 309 |
"_id": "[email protected]", |
| 310 |
"dist": { |
| 311 |
"shasum": "31732adeae78f1d2d60a29b63baf6a032df7c25d", |
| 312 |
"tarball": "https://registry.npmjs.org/slide/-/slide-1.1.5.tgz" |
| 313 |
}, |
| 314 |
"_from": ".", |
| 315 |
"_npmVersion": "1.3.8", |
| 316 |
"_npmUser": { |
| 317 |
"name": "isaacs", |
| 318 |
"email": "[email protected]" |
| 319 |
}, |
| 320 |
"maintainers": [ |
| 321 |
{ |
| 322 |
"name": "isaacs", |
| 323 |
"email": "[email protected]" |
| 324 |
} |
| 325 |
], |
| 326 |
"directories": {} |
| 327 |
}, |
| 328 |
"1.1.6": { |
| 329 |
"name": "slide", |
| 330 |
"version": "1.1.6", |
| 331 |
"author": { |
| 332 |
"name": "Isaac Z. Schlueter", |
| 333 |
"email": "[email protected]", |
| 334 |
"url": "http://blog.izs.me/" |
| 335 |
}, |
| 336 |
"contributors": [ |
| 337 |
{ |
| 338 |
"name": "S. Sriram", |
| 339 |
"email": "[email protected]", |
| 340 |
"url": "http://www.565labs.com" |
| 341 |
} |
| 342 |
], |
| 343 |
"description": "A flow control lib small enough to fit on in a slide presentation. Derived live at Oak.JS", |
| 344 |
"main": "./lib/slide.js", |
| 345 |
"dependencies": {}, |
| 346 |
"devDependencies": {}, |
| 347 |
"engines": { |
| 348 |
"node": "*" |
| 349 |
}, |
| 350 |
"repository": { |
| 351 |
"type": "git", |
| 352 |
"url": "git://github.com/isaacs/slide-flow-control.git" |
| 353 |
}, |
| 354 |
"license": "ISC", |
| 355 |
"gitHead": "8345e51ee41e35825abc1a40750ea11462f57028", |
| 356 |
"bugs": { |
| 357 |
"url": "https://github.com/isaacs/slide-flow-control/issues" |
| 358 |
}, |
| 359 |
"homepage": "https://github.com/isaacs/slide-flow-control", |
| 360 |
"_id": "[email protected]", |
| 361 |
"scripts": {}, |
| 362 |
"_shasum": "56eb027d65b4d2dce6cb2e2d32c4d4afc9e1d707", |
| 363 |
"_from": ".", |
| 364 |
"_npmVersion": "2.0.0-beta.3", |
| 365 |
"_npmUser": { |
| 366 |
"name": "isaacs", |
| 367 |
"email": "[email protected]" |
| 368 |
}, |
| 369 |
"maintainers": [ |
| 370 |
{ |
| 371 |
"name": "isaacs", |
| 372 |
"email": "[email protected]" |
| 373 |
} |
| 374 |
], |
| 375 |
"dist": { |
| 376 |
"shasum": "56eb027d65b4d2dce6cb2e2d32c4d4afc9e1d707", |
| 377 |
"tarball": "https://registry.npmjs.org/slide/-/slide-1.1.6.tgz" |
| 378 |
}, |
| 379 |
"directories": {} |
| 380 |
} |
| 381 |
}, |
| 382 |
"maintainers": [ |
| 383 |
{ |
| 384 |
"email": "[email protected]", |
| 385 |
"name": "nlf" |
| 386 |
}, |
| 387 |
{ |
| 388 |
"email": "[email protected]", |
| 389 |
"name": "ruyadorno" |
| 390 |
}, |
| 391 |
{ |
| 392 |
"email": "[email protected]", |
| 393 |
"name": "darcyclarke" |
| 394 |
}, |
| 395 |
{ |
| 396 |
"email": "[email protected]", |
| 397 |
"name": "adam_baldwin" |
| 398 |
}, |
| 399 |
{ |
| 400 |
"email": "[email protected]", |
| 401 |
"name": "isaacs" |
| 402 |
} |
| 403 |
], |
| 404 |
"author": { |
| 405 |
"name": "Isaac Z. Schlueter", |
| 406 |
"email": "[email protected]", |
| 407 |
"url": "http://blog.izs.me/" |
| 408 |
}, |
| 409 |
"time": { |
| 410 |
"modified": "2020-10-13T05:05:13.988Z", |
| 411 |
"created": "2011-01-13T21:21:32.280Z", |
| 412 |
"1.0.0": "2011-01-13T21:21:32.280Z", |
| 413 |
"1.0.1": "2011-01-13T21:21:32.280Z", |
| 414 |
"1.1.0": "2011-02-03T19:17:03.150Z", |
| 415 |
"1.1.1": "2011-03-17T04:10:26.257Z", |
| 416 |
"1.1.2": "2011-07-20T09:29:21.068Z", |
| 417 |
"1.1.3": "2011-07-27T20:22:03.040Z", |
| 418 |
"1.1.4": "2013-04-29T15:33:13.142Z", |
| 419 |
"1.1.5": "2013-08-19T22:27:46.044Z", |
| 420 |
"1.1.6": "2014-09-12T23:34:41.727Z" |
| 421 |
}, |
| 422 |
"repository": { |
| 423 |
"type": "git", |
| 424 |
"url": "git://github.com/isaacs/slide-flow-control.git" |
| 425 |
}, |
| 426 |
"users": { |
| 427 |
"agnat": true, |
| 428 |
"stdarg": true, |
| 429 |
"matteo.collina": true, |
| 430 |
"jian263994241": true, |
| 431 |
"hal9zillion": true, |
| 432 |
"mattmcfarland": true, |
| 433 |
"lgomez": true, |
| 434 |
"gekowa": true, |
| 435 |
"wangnan0610": true |
| 436 |
}, |
| 437 |
"readme": "# Controlling Flow: callbacks are easy\n\n## What's actually hard?\n\n- Doing a bunch of things in a specific order.\n- Knowing when stuff is done.\n- Handling failures.\n- Breaking up functionality into parts (avoid nested inline callbacks)\n\n\n## Common Mistakes\n\n- Abandoning convention and consistency.\n- Putting all callbacks inline.\n- Using libraries without grokking them.\n- Trying to make async code look sync.\n\n## Define Conventions\n\n- Two kinds of functions: *actors* take action, *callbacks* get results.\n- Essentially the continuation pattern. Resulting code *looks* similar\n to fibers, but is *much* simpler to implement.\n- Node works this way in the lowlevel APIs already, and it's very flexible.\n\n## Callbacks\n\n- Simple responders\n- Must always be prepared to handle errors, that's why it's the first argument.\n- Often inline anonymous, but not always.\n- Can trap and call other callbacks with modified data, or pass errors upwards.\n\n## Actors\n\n- Last argument is a callback.\n- If any error occurs, and can't be handled, pass it to the callback and return.\n- Must not throw. Return value ignored.\n- return x ==> return cb(null, x)\n- throw er ==> return cb(er)\n\n```javascript\n// return true if a path is either\n// a symlink or a directory.\nfunction isLinkOrDir (path, cb) {\n fs.lstat(path, function (er, s) {\n if (er) return cb(er)\n return cb(null, s.isDirectory() || s.isSymbolicLink())\n })\n}\n```\n\n# asyncMap\n\n## Usecases\n\n- I have a list of 10 files, and need to read all of them, and then continue when they're all done.\n- I have a dozen URLs, and need to fetch them all, and then continue when they're all done.\n- I have 4 connected users, and need to send a message to all of them, and then continue when that's done.\n- I have a list of n things, and I need to dosomething with all of them, in parallel, and get the results once they're all complete.\n\n\n## Solution\n\n```javascript\nvar asyncMap = require(\"slide\").asyncMap\nfunction writeFiles (files, what, cb) {\n asyncMap(files, function (f, cb) {\n fs.writeFile(f, what, cb)\n }, cb)\n}\nwriteFiles([my, file, list], \"foo\", cb)\n```\n\n# chain\n\n## Usecases\n\n- I have to do a bunch of things, in order. Get db credentials out of a file,\n read the data from the db, write that data to another file.\n- If anything fails, do not continue.\n- I still have to provide an array of functions, which is a lot of boilerplate,\n and a pita if your functions take args like\n\n```javascript\nfunction (cb) {\n blah(a, b, c, cb)\n}\n```\n\n- Results are discarded, which is a bit lame.\n- No way to branch.\n\n## Solution\n\n- reduces boilerplate by converting an array of [fn, args] to an actor\n that takes no arguments (except cb)\n- A bit like Function#bind, but tailored for our use-case.\n- bindActor(obj, \"method\", a, b, c)\n- bindActor(fn, a, b, c)\n- bindActor(obj, fn, a, b, c)\n- branching, skipping over falsey arguments\n\n```javascript\nchain([\n doThing && [thing, a, b, c]\n, isFoo && [doFoo, \"foo\"]\n, subChain && [chain, [one, two]]\n], cb)\n```\n\n- tracking results: results are stored in an optional array passed as argument,\n last result is always in results[results.length - 1].\n- treat chain.first and chain.last as placeholders for the first/last\n result up until that point.\n\n\n## Non-trivial example\n\n- Read number files in a directory\n- Add the results together\n- Ping a web service with the result\n- Write the response to a file\n- Delete the number files\n\n```javascript\nvar chain = require(\"slide\").chain\nfunction myProgram (cb) {\n var res = [], last = chain.last, first = chain.first\n chain([\n [fs, \"readdir\", \"the-directory\"]\n , [readFiles, \"the-directory\", last]\n , [sum, last]\n , [ping, \"POST\", \"example.com\", 80, \"/foo\", last]\n , [fs, \"writeFile\", \"result.txt\", last]\n , [rmFiles, \"./the-directory\", first]\n ], res, cb)\n}\n```\n\n# Conclusion: Convention Profits\n\n- Consistent API from top to bottom.\n- Sneak in at any point to inject functionality. Testable, reusable, ...\n- When ruby and python users whine, you can smile condescendingly.\n", |
| 438 |
"readmeFilename": "README.md", |
| 439 |
"homepage": "https://github.com/isaacs/slide-flow-control", |
| 440 |
"contributors": [ |
| 441 |
{ |
| 442 |
"name": "S. Sriram", |
| 443 |
"email": "[email protected]", |
| 444 |
"url": "http://www.565labs.com" |
| 445 |
} |
| 446 |
], |
| 447 |
"bugs": { |
| 448 |
"url": "https://github.com/isaacs/slide-flow-control/issues" |
| 449 |
}, |
| 450 |
"license": "ISC" |
| 451 |
} |