Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/Sage/streamlinejs
Browse files Browse the repository at this point in the history
  • Loading branch information
bjouhier committed Nov 17, 2012
2 parents e56ee30 + cc9c7c9 commit 23493a0
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
10 changes: 10 additions & 0 deletions .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/
27 changes: 27 additions & 0 deletions 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'

0 comments on commit 23493a0

Please sign in to comment.