HaxeBridges is a library which allows a single project to be compiled into separate parts, and for separate platforms.
This is useful for many situations, including when multi-threading, client/server, etc.

The idea is that your main application should be able to naturally use objects which will be published via a different platform/compile.

The example included in the repository now is a simple example of creating a worker thread (flash only for the moment).

In the main class:

1
2
3
4
 var obj = new ObjectInsideWorker();
 obj.nonStaticMethod(function(result){
    trace("Worker result: "+result);
 });

And the class which gets compiled into the worker:

1
2
3
4
5
6
7
8
9
10
package;
class ObjectInsideWorker{
 
 public function new(){
 }

 public function nonStaticMethod():String{
    return "nonStaticMethod: "+Std.string(Math.round(Math.random() * 1000));
 }
}

Then all that’s required is a compiler argument to get things working:

1
--macro Bridge.add('ObjectInsideWorker', 'Worker')

(first argument is a comma separated list of classes to be included in the worker)

More examples and bridge-types to come.
Check out the repository here.