easyWorker is a library to easily implement Workers. The main goal of the library is to lift the burden of creating another project and/or an extra SWF to use Workers, everything is in-memory. As a result developer don’t have to deal anymore with MessageChannel
and other low level classes, just use the high level classes Thread
an Events
.
When using the Thread
class, a developer must provide his own class that will run in as a the new worker. Before the thread creation, a few events can be listened to monitor the worker, such as if it has finished processing its task. The library is able to automatically register typed object to pass them back and forth the Worker.
Sample
public class ComplexWorker implements Runnable { // Mandatory declaration if you want your Worker be able to communicate. // This CrossThreadDispatcher is injected at runtime. public var dispatcher:CrossThreadDispatcher; public function run(args:Array):void { const values:TermsVo = args[0] as TermsVo; dispatcher.dispatchResult(add(values)); } private function add(obj:TermsVo):Number { return obj.v1 + obj.v2; } } var _thread:IThread; function startApp():void { _thread = new Thread(ComplexWorker, "nameOfMyThread"); _thread.addEventListener(ThreadProgressEvent.PROGRESS, thread_progressHandler); _thread.addEventListener(ThreadResultEvent.RESULT, thread_resultHandler); _thread.addEventListener(ThreadFaultEvent.FAULT, thread_faultHandler); _thread.start(new TermsVo(1, 2)); }
RT @as3gamegears: New: easyWorker (lib to easily implement Workers) http://t.co/FEChJMAIfF #as3 #flash #gamedev
Vicente Fleitas liked this on Facebook.