Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/Sage/streamlinejs
- Loading branch information
Showing
2 changed files
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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' | |||
|