Skip to content

Commit 46dd0ae

Browse files
committed
Readded functions main/run/do/from to rewrite
1 parent 07c6a33 commit 46dd0ae

File tree

2 files changed

+73
-0
lines changed

2 files changed

+73
-0
lines changed

async.coffee

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,33 @@ async = (genFunc) -> asyncFunc = (args...) ->
5757
# Start our own iterator to begin running the async function
5858
iter.next()
5959

60+
async.run = (func, errCallback=console.log) ->
61+
### This tries running the async function given and if it
62+
fails it calls the errCallback with the error given
63+
by the async function
64+
###
65+
do async ->
66+
try
67+
yield async(func)()
68+
catch err
69+
errCallback(err)
70+
71+
async.main = (func) ->
72+
### Although async.run has errCallback as console.log we'll just print
73+
the stack
74+
###
75+
async.run func, (err) ->
76+
console.log err.stack
77+
78+
async.from = (iterable) ->
79+
### Creates a async function from an existing iterable ###
80+
genFunc = -> yield from iterable
81+
return async(genFunc)
82+
83+
async.do = async.run
84+
85+
Object.defineProperty(async, "name", value: "async")
86+
6087
if module?
6188
module.exports = async
6289
else

async.js

Lines changed: 46 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)