# Class: Promise

## Constructor

#### new Promise()

  jQuery promise, created from jQuery.Deferred object. See jQuery docs for more detailed information.
  Promised are used to resolve server responses to requests performed by AvayaClientServices.

  See async for more information.

  Note that since all Promise methods return themselves, the methods can be easily chained.

  ##### Examples

  Adding participants to a conversation

      var successCallback = function(){
           console.log("Participants added!");
      };
      var failCallback = function(){
           console.log("Error");
      };
      conversation.addParticipants(participants).then(successCallback, failCallback);
      // do something else...
      // when the Promise is resolved, console will print "Participants added!"

  Chaining methods

      conversation.addParticipants(participants).done(doOneThing).done(doOther).done(doAnother).fail(onError);

## Methods

#### always(alwaysCallback) → {AvayaClientServices.Base.Promise}

  Add handlers to be called when the Deferred object is either resolved or rejected.

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `alwaysCallback` | function | A function, or array of functions, that is called when the Deferred is resolved or rejected.

  ##### Returns:

  { AvayaClientServices.Base.Promise }

#### done(doneCallback) → {AvayaClientServices.Base.Promise}

  Add handlers to be called when the Deferred object is resolved.

  ##### Example

      conversation.addParticipants(participants).done(function(data){
           //invoked on success
           //e.g. refresh the UI
      });

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `doneCallback` | function | A function, or array of functions, that are called when the Deferred is resolved.

  ##### Returns:

  { AvayaClientServices.Base.Promise }

#### fail(failCallback) → {AvayaClientServices.Base.Promise}

  Add handlers to be called when the Deferred object is rejected.

  ##### Example

      conversation.addParticipants(participants).fail(function(error){
           //invoked on failure
           //e.g. show error in UI
      });

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `failCallback` | function | A function, or array of functions, that are called when the Deferred is rejected.

  ##### Returns:

  { AvayaClientServices.Base.Promise }

#### progress(progressCallback) → {AvayaClientServices.Base.Promise}

  Add handlers to be called when the Deferred object generates progress notifications. Please note that not every Promise
  creates progress notifications.

  ##### Example

      conversation.addParticipants(participants).progress(function(progressObject){
           //invoked on progress
           //e.g. refresh progress bar
      });

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `progressCallback` | function | A function, or array of functions, to be called when the Deferred generates progress notifications.

  ##### Returns:

  { AvayaClientServices.Base.Promise }

#### state() → {String}

  Determine the current state of a Deferred object.

  ##### Returns:

  { String }

#### then(doneCallback, failCallback, progressCallback) → {AvayaClientServices.Base.Promise}

  Add handlers to be called for the Deferred object. Combines functionality of .done(), .fail() and .progress().

  ##### Example

      conversation.addParticipants(participants).then(function(data){
           //invoked on success
           //e.g. refresh the UI
      }, function(error){
           //invoked on failure
           //e.g. show error in UI
      }, function(progressObject){
           //invoked on progress
           //e.g. refresh progress bar
      });

  ##### Parameters:

  Name | Type | Argument | Description
  --- | --- | --- | ---
  `doneCallback` | function |  | A function that is called when the Deferred is resolved.
  `failCallback` | function | <optional> | A function that is called when the Deferred is rejected.
  `progressCallback` | function | <optional> | A function that is called when the Deferred generates progress notifications.

  ##### Returns:

  { AvayaClientServices.Base.Promise }