rpc now can handle args
This commit is contained in:
parent
91972107eb
commit
f3a13e4247
@ -14,7 +14,7 @@ class HelloWorld implements Process {
|
||||
|
||||
var c = new HelloWorldServiceRPC(0);
|
||||
|
||||
c.getNumber().handle((res) -> {
|
||||
c.getNumber(2,3).handle((res) -> {
|
||||
Log.debug("Got number: " + res);
|
||||
});
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
package bin;
|
||||
|
||||
import kernel.log.Log;
|
||||
import macros.rpc.RPC;
|
||||
import kernel.ps.ProcessHandle;
|
||||
import kernel.ps.Process;
|
||||
@ -19,7 +20,9 @@ class HelloWorldService implements Process {
|
||||
}
|
||||
|
||||
@rpc
|
||||
public function getNumber():Int {
|
||||
public function getNumber(arg1: Int, arg2: Int):Int {
|
||||
Log.debug(arg1);
|
||||
Log.debug(arg2);
|
||||
return 42;
|
||||
}
|
||||
}
|
||||
|
@ -25,13 +25,15 @@ class RPC {
|
||||
|
||||
switch (field.kind) {
|
||||
case FFun(f):
|
||||
var argsExprs:Array<Expr> = [for (a in f.args) macro $i{a.name}];
|
||||
|
||||
c.fields.push({
|
||||
name: field.name,
|
||||
pos: field.pos,
|
||||
kind: FFun({
|
||||
args: f.args,
|
||||
expr: macro {
|
||||
return cast this._performRequest($v{field.name}, []);
|
||||
return cast this._performRequest($v{field.name}, $a{argsExprs});
|
||||
},
|
||||
ret: TPath({name: "Promise", params: [TPType(f.ret)], pack: ["tink", "core"]}),
|
||||
}),
|
||||
@ -64,12 +66,22 @@ class RPC {
|
||||
switch (field.kind) {
|
||||
case FMethod(k):
|
||||
var funName = field.name;
|
||||
exprs.push(macro {
|
||||
if (pack.data.func == $v{funName}) {
|
||||
pack.respond(this.$funName());
|
||||
}
|
||||
});
|
||||
|
||||
var exprsType = field.expr().t;
|
||||
|
||||
switch (exprsType){
|
||||
case TFun(args, ret):
|
||||
var callArgs = [for (k => v in args) macro pack.data.args[$v{k}]];
|
||||
|
||||
// TODO: transform this to a switch statement
|
||||
exprs.push(macro {
|
||||
if (pack.data.func == $v{funName}) {
|
||||
pack.respond(this.$funName($a{callArgs}));
|
||||
}
|
||||
});
|
||||
default:
|
||||
Context.error("Only functions can be used for rpc", field.pos);
|
||||
}
|
||||
default:
|
||||
Context.error("Only functions can be used for rpc", field.pos);
|
||||
}
|
||||
|
@ -18,7 +18,7 @@ abstract class RPCBase {
|
||||
private function _performRequest(func:String, args:Array<Dynamic>):Promise<Dynamic> {
|
||||
return Net.sendAndAwait(id, this._proto, {
|
||||
func: func,
|
||||
// args: args
|
||||
args: args
|
||||
}).map((res) -> {
|
||||
switch (res) {
|
||||
case Success(pack):
|
||||
|
Loading…
Reference in New Issue
Block a user