Comparing version 1.3.3 to 1.3.4
38
index.js
@@ -53,3 +53,3 @@ 'use strict'; // always strict mode | ||
// Give child class instance a copy of this/RPC | ||
if (child._handleRpc != null) child._handleRpc (this); | ||
if (child != null && child._handleRpc != null) child._handleRpc (this); | ||
@@ -112,6 +112,18 @@ // Set private variables | ||
let params = call.params.map ((param) => { | ||
if (param.isFunc) { | ||
return (...fnParams) => { | ||
this._stream.send ('cbRes.' + param.funcId, { | ||
params: fnParams, | ||
}); | ||
} | ||
} else { | ||
return param.data; | ||
} | ||
}) | ||
// Try getting response from handler or handle error | ||
try { | ||
// Run with applied params and await result | ||
response = await handler (...call.params); | ||
response = await handler (...params); | ||
} catch (err) { | ||
@@ -139,2 +151,22 @@ // Emit error as response | ||
let parsedParams = params.map ((param) => { | ||
if (typeof param == "function") { | ||
let funcId = uuid (); | ||
this._stream.on ('cbRes.' + funcId, (res) => { | ||
param (...res.params); | ||
}); | ||
return { | ||
isFunc: true, | ||
funcId: funcId, | ||
} | ||
} else { | ||
return { | ||
isFunc: false, | ||
data: param, | ||
} | ||
} | ||
}); | ||
// Emit the remote call event | ||
@@ -144,3 +176,3 @@ this._stream.send ('fnCall', { | ||
resId: resId, | ||
params: params, | ||
params: parsedParams, | ||
}); | ||
@@ -147,0 +179,0 @@ |
{ | ||
"name": "arc-rpc", | ||
"version": "1.3.3", | ||
"version": "1.3.4", | ||
"description": "Asynchronous Remote Classes make RPC simple", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
12200
277