     fiber.throwInto.bind fiber
   )
 
-  $fiber.yield()
+  return $fiber.yield()
 
 $wait.register = ->
   throw new Error 'something has already been registered' if $wait._stash
 
-  deferred = $Promise.defer()
-  $wait._stash = deferred.promise
+  resolve = reject = null
+  $wait._stash = new $Promise (resolve_, reject_) ->
+    resolve = resolve_
+    reject = reject_
+    return
 
-  deferred.callback
+  return (error, result) ->
+    if error
+      reject error
+    else
+      resolve result
+    return
 
 #=====================================================================
 
 module.exports = {
+  $coroutine
   $fiberize
-  $coroutine
   $waitEvent
   $wait
 }

        process.nextTick ->
          throw error
    ).run()

# Makes a function run in its own fiber and returns a promise.
$coroutine = (fn) ->
  (args...) ->
    new $Promise (resolve, reject) ->
      $fiber(=>
        try
          resolve fn.apply this, args
        catch error
          reject error
      ).run()

# Waits for an event.
#

  handler = (args...) ->
    emitter.removeListener 'error', errorHandler
    fiber.run args
    return
  errorHandler = (error) ->
    emitter.removeListener event, handler
    fiber.throwInto error
    return

  emitter.once event, handler
  emitter.once 'error', errorHandler

  return $fiber.yield()

# Waits for a promise or a continuable to end.
#
