Skip to content

Promises (and Deferreds) for ActionScript 3.0

Notifications You must be signed in to change notification settings

moodev/promise-as3

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 

Repository files navigation

Promises for Actionscript 3

Attention Developers

All work is currently in the develop branch
A detailed README is also availble in the develop branch.

Introduction

The repository provides a AS3 library of futures as defined by CommonJS.

A promise (aka Future) is an object thats acts as a proxy for a result that my not be initially known, usually because the computation of its value has not yet completed. Developers defer processing by returning a promise to respond later. A promiseis essentially a read-only version of the deferredresponse.

  • new Deferred()

    • can add callbacks
    • can be resolved or rejected
    • can **promise()**to let you know what happened
       
  • Promise (accessed via new Deferred().promise)

    • can add callbacks
    • Can't resolve, so you know it's legit when it does
    • Can check resolve status
    • Can cancel (only in AS3 version)

 

Popularized in the jQuery javascript library, Deferred(s) are now available for AS3 developers. This library emulates the jQuery v1.7 feature set of futures: Deferred, Promise, and Callbacks. This library also supports two syntactical approaches familiar to either jQuery users or Actionscript/Flex developers.

Flex developers often use components asynchronously:

  • setTimeOut()
  • setInterval()
  • callLater()
  • Timer
  • Loader
  • URLLoader
  • HTTPService
  • RemoteObject
  • WebService
  • NetStream
  • Socket
  • NetConnection
  • SharedObject

The above components, unfortunately, do not have a consistent mechanism in which developers may handle the asynchronous responses… until now! With the above components developers would use:

  • addEventListener()
  • Responders
  • AsyncToken
  • closures (aka callbacks)

Why Deferred(s)

Now developers can employ Deferred.as to build promises of responses. The interface is always the same regardless of the component/mechanism used to fulfill the promise.

The biggest advantages are

  1. Consistent, intuitive API for attaching handlers to asynchronous processes
  2. Ability to intercept and transform results before handlers are called
  3. Ability to chain futures in sequence
  4. Ability to process futures in parallel (aka batch processing)

Learning Resources

 

About

Promises (and Deferreds) for ActionScript 3.0

Resources

Stars

Watchers

Forks

Packages

No packages published