Last active
December 16, 2015 09:19
-
-
Save sonygod/5412347 to your computer and use it in GitHub Desktop.
haxe flash js remoting use async flash---async ---js js----async--flash
this version only work on firefox, I don't know why ,maybe haxe Timer ge tsomthing wrong. try to build this ,you need tinkerbell r6388 , hx-async full code and project here
https://github.com/sonygod/fj_aync
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package ; | |
| import haxe.ds.ObjectMap; | |
| import haxe.ds.StringMap; | |
| import haxe.Timer; | |
| import haxe.remoting.ExternalConnection; | |
| import tink.lang.Cls; | |
| import Format; | |
| /** | |
| * ... | |
| * @author sonygod | |
| */ | |
| class FlashMain { | |
| public function foo(x, y) { trace("outsidecall" + x + y); } | |
| static var js:ExternalConnection = null; | |
| static var hello; | |
| public static var onData: Dynamic; | |
| public static function main() { | |
| var ctx = new haxe.remoting.Context(); | |
| ctx.addObject("FlashMain", FlashMain); | |
| js = haxe.remoting.ExternalConnection.jsConnect("default", ctx); | |
| var arr:Array<Int> = [1, 2]; | |
| var arr2=arr.slice(0, arr.length - 1); | |
| hello = new Forwarder(js); | |
| hello.sayHello("hi", "god", onCalljs); | |
| } | |
| public static function onCalljs(err, data) { | |
| trace("回来了,靠"+err+data); | |
| } | |
| public static function __onData(args: Array<Dynamic>) { | |
| //trace(args.toString() + "" + Timer.stamp() * 1000); | |
| var recall = args.pop(); | |
| trace(args.toString() + "" + Timer.stamp() * 1000); | |
| var xxx:StringMap<CallBackObjWithFun> = js.getcallBackList(); | |
| var f :CallBackObjWithFun= xxx.get(recall.id + recall.name); | |
| trace(f.id+f.name+f.callBack); | |
| Reflect.callMethod(FlashMain, f.callBack, args); | |
| } | |
| private static function __init__() : Void { | |
| onData = Reflect.makeVarArgs(__onData); | |
| } | |
| } | |
| class Forwarder implements Cls { | |
| var fields:Hash<Dynamic> = new Hash<Dynamic>(); | |
| public var recallFuns:ObjectMap<Caller ,Dynamic>=new ObjectMap<Caller ,Dynamic>(); | |
| @:forward(!multiply) var target:ExternalConnection; | |
| @:forward function fwd2(hello:HelloService) { | |
| get: fields.get($name), | |
| set: fields.set($name, param), | |
| call:target.resolve("main").resolve("onData").call($argsRemoting) | |
| } | |
| public function new(target) { | |
| this.target = target; | |
| } | |
| } | |
| typedef Caller = { | |
| id:String, | |
| name:String | |
| } | |
Author
Author
package ;
import js.Browser;
import haxe.remoting.ExternalConnection;
import Format;
class JsMain {
public static var cnx = null;
static var ctx = null;
public static var onData: Dynamic;
private static function __init__() : Void {
onData = Reflect.makeVarArgs(__onData);
}
public static function main() {
ctx = new haxe.remoting.Context();
ctx.addObject("main",JsMain);
cnx = ExternalConnection.flashConnect("default", "myFlashObject", ctx);
}
//http://www.verydemo.com/demo_c98_i5393.html
public static function __onData(args: Array<Dynamic>) {
Browser.window.alert("length=" + args[2].id);
Test.bubblesort([1, 2, 9, 7, 6, 0.3], function (err, data) {
cnx = ExternalConnection.flashConnect("default", "myFlashObject", ctx);
cnx.FlashMain.onData.call([err,data,args[2]]);
} );
}
}
Author
package ;
/**
- ...
- @author sonygod
*/
import async.Build;
import async.Async;
import haxe.Timer;
import org.transition9.async.Step;
using org.transition9.async.AsyncLambda;
class Test implements Build
{
static function asyncGet2<T1, T2>(v1:T1, v2:T2, cb){
cb(null, v1, v2);
}
@async(var ret: Array<Float>) public static function bubblesort(array : Array<Float>) {
var swapping = false;
var temp : Float;
while (!swapping) {
swapping = true;
for (i in 0...array.length) {
[]=delay(1);
if (array[i] > array[i+1]) {
temp = array[i+1];
array[i+1] = array[i];
array[i] = temp;
swapping = false;
}
}
}
return array;
}
@async(var ret: Array<Float>) static function asynchronous(){
var arry:Array<Float>;
[ arry] = bubblesort([1337, 1, -465, 3.141592653589793, 789, 69, 789, -132, 3.141592653589793, 465, 789, 0, 27]);
return arry;
}
static function bubblesortSync(array : Array<Float>) {
var swapping = false;
var temp : Float;
while (!swapping) {
swapping = true;
for (i in 0...array.length) {
if (array[i] > array[i+1]) {
temp = array[i+1];
array[i+1] = array[i];
array[i] = temp;
swapping = false;
}
}
}
return array;
}
public static function getResult(err:NodeErr, data:Array<Float>) {
trace("end"+(Timer.stamp()*1000-startTime));
trace(data);
}
@async(var ret:Bool) public static function doFooParallel(arrayData:Array<Float>) {
trace(Timer.stamp() * 10000 + "" + arrayData);
return true;
};
//
@async(var ret:Bool) public static function doFooGroup(?arg1:String) {
trace(Timer.stamp() * 10000 + "doFooGroup" + arg1);
return true;
};
@async(var ret:Bool)public static function doSomethingElseAsync(array) {
trace(Timer.stamp() * 10000 + " doSomethingElseAsync" + array);
return true;
};
@async(var ret:Int) public static function doSomethingElseAsync2(element:Int ) {
trace(element);
return element;
};
@async(var ret:Int,var ret2:String) public static function doSomethingElseAsync3(element:Int ) {
return many(element, "1");
};
public static var startTime:Float;
public static function main() {
var step = new Step();
step.chain([
function () {
bubblesort([2, 1, 4, 7], step.cb);
},
function (err, arrayData) {
doFooParallel(arrayData, step.parallel());
doFooParallel(arrayData, step.parallel());
doFooParallel(arrayData, step.parallel());
}
,function (err, ?arg1,?arg2,?arg3) {
// trace("finish now..."+Timer.stamp()+"arg"+arg1+arg2+arg3);
doFooGroup("group1", step.group());
doFooGroup("group1", step.group());
doFooGroup("group1", step.group());
}
,function (err, args) {
trace("finish"+args);
}
]);
var fromArray = [1, 2, 3, 4];
var onElement = function (element :Int, cb :String->Int->Void) {
platformDelay(100,function () {
cb("Some int=" + element,1);
});
}
var onFinish = function (err :Dynamic, result1:String->Int->Void) {
if (err != null) trace("Oh no: " + err);
trace("result=" + result1);
}
//AsyncLambda.map( fromArray,onElement , onFinish);
doSomethingElseAsync3(1, function(err:String, e:Int,s:String):Void { trace("e=========="+e); } );
}
static inline function delay(ms:Int, cb){
platformDelay(ms, function(){ trace(ms+' passed'); cb(null); });
}
static inline function platformDelay(ms:Int, fun){
if (cpp || neko || php) fun(); #else haxe.Timer.delay(fun, ms); #end
}
}
typedef NodeErr = Null;
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
package tink.lang.macros;
import haxe.macro.Context;
import haxe.macro.Expr;
import haxe.macro.Type;
import tink.macro.build.Member;
import tink.macro.build.MemberTransformer;
using tink.macro.tools.MacroTools;
using StringTools;
using Lambda;
using tink.core.types.Outcome;
typedef ClassFieldFilter = ClassField->Bool;
typedef ForwardRules = { call:Null, get:Null, set:Null };
class Forward {
static inline var TAG = ":forward";
static public function process(ctx:ClassBuildContext) {
new Forward(ctx.has, ctx.add, ctx.cls.isInterface).processMembers(ctx.members);
}
var hasField:String->Bool;
var addField:Member->?Bool->Member;
var ownerIsInterface:Bool;
function new(hasField, addField, ownerIsInterface) {
this.hasField = hasField;
this.addField = addField;
this.ownerIsInterface = ownerIsInterface;
}
function processMembers(members:Array) {
for (member in members)
switch (member.extractMeta(TAG)) {
case Success(tag):
switch (member.kind) {
case FVar(t, ):
forwardTo(member, t, tag.pos, tag.params);
case FProp(, _, t, _):
forwardTo(member, t, tag.pos, tag.params);
case FFun(f):
member.excluded = true;
forwardWithFunction(f, tag.pos, tag.params);
}
default:
}
}