This Confluence has been LDAP enabled, if you are an ASF Committer, please use your LDAP Credentials to login. Any problems file an INFRA jira ticket please.

Child pages
  • AS3 Promises - a guide and example

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Introduction

xxx

Hello world

https://promisesaplus.com/

http://spring.io/understanding/javascript-promises
http://www.html5rocks.com/en/tutorials/es6/promises/

You need to make 'ordinary' components Promise-ready.

Main.xml (package: default package)

...

Code Block
themeEclipse
languageactionscript3
linenumberstrue
package nl.ixms
{

import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
import mx.rpc.http.HTTPService;

import org.apache.flex.promises.Promise;
import org.apache.flex.promises.interfaces.IThenable;

public class HTTPServicePromise extends HTTPService
{

	public function HTTPServicePromise(rootURL:String=null, destination:String=null)
	{
		super(rootURL, destination);
	}

	public function sendWithPromise(parameters:Object=null):IThenable
	{
		return new Promise(function (fulfill:Function = null,
									 reject:Function = null):* {
			
			/* Link the service result events with the promise handlers */
			addEventListener(ResultEvent.RESULT, function (event:ResultEvent):void {
				fulfill(event.result);
			});

			addEventListener(FaultEvent.FAULT, function (event:FaultEvent):void {
				reject(event.message);
			});

			send(parameters);
		});
	}

}
}