Minor updates.

This commit is contained in:
Julien Fontanet 2014-01-15 16:33:38 +01:00
parent f336832395
commit 0e2e54778d

View File

@ -45,6 +45,7 @@ $synchronize = (fn, ctx) ->
(args...) -> (args...) ->
fiber = $fiber.current fiber = $fiber.current
throw new Error 'not running in a fiber' unless fiber?
args.push (error, result) -> args.push (error, result) ->
if error? if error?
@ -60,6 +61,7 @@ $synchronize = (fn, ctx) ->
# Note: if the *error* event is emitted, this function will throw. # Note: if the *error* event is emitted, this function will throw.
$waitEvent = (emitter, event) -> $waitEvent = (emitter, event) ->
fiber = $fiber.current fiber = $fiber.current
throw new Error 'not running in a fiber' unless fiber?
errorHandler = null errorHandler = null
handler = (args...) -> handler = (args...) ->
@ -77,7 +79,6 @@ $waitEvent = (emitter, event) ->
# Waits for a promise or a thunk to end. # Waits for a promise or a thunk to end.
$wait = (value) -> $wait = (value) ->
fiber = $fiber.current fiber = $fiber.current
throw new Error 'not running in a fiber' unless fiber? throw new Error 'not running in a fiber' unless fiber?
if $isPromise value if $isPromise value
@ -93,6 +94,8 @@ $wait = (value) ->
else else
fibre.run result fibre.run result
else else
# TODO: handle array and object of promises/thunks.
# No idea what is it, just forwards. # No idea what is it, just forwards.
return value return value