diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..3a0675f8 --- /dev/null +++ b/.gitignore @@ -0,0 +1,10 @@ +# ignore those pesky files that Mac generates +.DS_Store + +# ignore streamline temp files +tmp--* + +npm-debug.log + +# ignore the node inclusion directory +node_modules/ diff --git a/examples/flows/http._coffee b/examples/flows/http._coffee new file mode 100644 index 00000000..a6aeb789 --- /dev/null +++ b/examples/flows/http._coffee @@ -0,0 +1,27 @@ +# a minimal example of using funneling to limit the concurrency of an operation. +# in this case, the operation to parallelize is making HTTP requests + +request = require 'request' +flows = require 'streamline/lib/util/flows' + +# get a page via HTTP +get_page = (_, page_number) -> + httpFunnel _, (_) -> + console.log 'request ' + page_number + response = request.get 'http://google.com?p=' + page_number, _ + console.log 'response ' + page_number + response.body + +httpFunnel = flows.funnel 15 # allow max 15 to run in parallel + +# add 50 pages to request +futures = (get_page null, page_number for page_number in [0..49]) + +console.log 'pages declared' + +# accumulate all of the responses before proceeding +results = flows.collect _, futures +# at this point, results is an array of bodies + +console.log 'job complete' +