Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Got the Basic Version up will not start adding tests, features and do…
…cumentation.
- Loading branch information
1 parent
cdd206f
commit 0d8e4ee
Showing
2 changed files
with
102 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,75 @@ | |||
|
|||
Narrow = require 'narrow' | |||
|
|||
### | |||
### | |||
module.exports = exports = (funcs, done_callback) -> | |||
### | |||
Called by Narrow on each Request Info Object. | |||
From here we the request and call Narrows' callback (fn) | |||
### | |||
narrow_request_item_callback = (task_info, callback) -> | |||
|
|||
if !task_info.params | |||
task_info.params = {} | |||
|
|||
### | |||
On Load | |||
### | |||
if task_info.load | |||
task_info.load(task_info.params) | |||
|
|||
### | |||
Perfom the task | |||
### | |||
task_info.task task_info.params, (err, result) -> | |||
if !err | |||
callback null, { | |||
result: true, | |||
value: result, | |||
name: task_info.name | |||
} | |||
else | |||
callback null, { | |||
result: false, | |||
error: err, | |||
name: task_info.name | |||
} | |||
|
|||
### | |||
On Complete | |||
### | |||
if task_info.complete | |||
task_info.load(task_info.params) | |||
|
|||
### | |||
Create the Narrow Instance to handle the Async Operation. | |||
### | |||
narrow = new Narrow 5, narrow_request_item_callback | |||
|
|||
### | |||
This is where we will store our results. | |||
### | |||
results = Object() | |||
|
|||
### | |||
Receives the Results and Creates a map for the cient | |||
### | |||
narrow.on('complete', (result) -> | |||
Object.defineProperty results, result.name, { | |||
value: result, | |||
writable: false, | |||
configurable: false | |||
} | |||
) | |||
|
|||
### | |||
Pushes all the Requests to the Pipeline and waits for the results. | |||
When the results are received we return it to the callback. | |||
### | |||
narrow.pushAll(funcs, -> | |||
done_callback results | |||
) |
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 @@ | |||
async_block = require '../' | |||
|
|||
async_block([ | |||
{ | |||
name: 'd1', | |||
task: (params, callback) -> | |||
callback null, 'testing 2' | |||
}, | |||
{ | |||
name: 'd2', | |||
task: (params, callback) -> | |||
callback 'Something went wrong!' | |||
} | |||
], (results) -> | |||
|
|||
if results.d1.result is true | |||
console.log "D1 Success: " + results.d1.value | |||
else | |||
console.log "D1 Fail: " + results.d1.value | |||
|
|||
|
|||
|
|||
if results.d2.result is true | |||
console.log "D1 Success: " + results.d2.value | |||
else | |||
console.log "D1 Fail: " + results.d2.value | |||
) |