 
     @started = true
 
+  # Setup a hook to reject the promise automatically after a given duration.
+  #
+  # timeout - The {Number} of milliseconds before the promise is rejected.
+  # message - The message {String} to use for the rejection.
   rejectAfter: (@timeout, @message) ->
 
+  ### Internal ###
+
+  # Notifies the different callbacks registered on this promise according
+  # to the promise state.
   notifyHandlers: ->
     if @fulfilled
       handler @value for handler in @fulfilledHandlers
     else
       handler @reason for handler in @errorHandlers
 
+  # Returns the signature of the passed-in function.
+  #
+  # func - The {Function} for which return the signature.
+  #
+  # Returns an {Array} of the function arguments.
   signature: (func) ->
     re = ///
       ^function

    @notifyHandlers()
    @pending = false

  reject: (reason) ->
    return unless @pending


# Public: A lightweight implementation of promises.
class agt.Promise

  ### Public ###

  # Returns an already fulfilled promise with the passed-in `value`.
  #
  # value - The promise's value.
  #
  # Returns a [Promise]{agt.Promise}.
  @unit: (value=0) ->
    new agt.Promise -> value

  # Returns a promise that is fulfilled when all the passed-in have been
  # fulfilled. The value of all the promised are provided in the returned
  # promise value.
  # If one of the promises fails, the returned promise is rejected.
  #
  # promises - An {Array} of promises
  #
  # Returns a [Promise]{agt.Promise}.
  @all: (promises) ->
    promise = new agt.Promise
    solved = 0
    results = []

    promises.forEach (p ,i) ->
      p
      .then (value) ->
        solved++
        results[i] = value
        promise.resolve results if solved is promises.length

      .fail (reason) ->
