Skip to content

Commit

Permalink
Require explicit _rkwargs marker (#212)
Browse files Browse the repository at this point in the history
  • Loading branch information
oeway authored Nov 1, 2021
1 parent fae9a67 commit be36ef0
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ The `decoder` function converts the encoded object into the actual object. It wi
### Remote function calls and arguments
Remote function call is almost the same as calling a local function. The arguments are mapped directly, for example, you can call a Python function `foo(a, b, c)` from javascript or vise versa. However, since Javascript does not support named arguments as Python does, ImJoy does the following conversion:
* For functions defined in Javascript, there is no difference when calling from Python
* For functions defined in Python, when calling from Javascript and if the last argument is an object, then it will be automatically converted into keyword arguments when calling the Python function. For example, if you have a Python function defined as `def foo(a, b, c=None):`, in Javascript, you should call it as `foo(9, 10, {c: 33})`.
* For functions defined in Python, when calling from Javascript, if the last argument is an object and its `_rkwargs` is set to true, then it will be converted into keyword arguments when calling the Python function. For example, if you have a Python function defined as `def foo(a, b, c=None):`, in Javascript, you should call it as `foo(9, 10, {c: 33, _rkwargs: true})`.

### Support Zarr Array encoding
[Zarr](https://zarr.readthedocs.io/en/stable/) is a more scalable n-dimensional array format that has a numpy-like api and can be used with multiple backends. It is ideally suited for sending large n-dimensional array between imjoy-rpc peers in a lazy fashion. We have an [internal implementation] of codec that can support sending.
Expand Down
2 changes: 1 addition & 1 deletion javascript/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion javascript/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "imjoy-rpc",
"version": "0.3.32",
"version": "0.3.33",
"description": "Remote procedure calls for ImJoy.",
"module": "index.js",
"scripts": {
Expand Down
9 changes: 6 additions & 3 deletions javascript/src/rpc.js
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,8 @@ export class RPC extends MessageEmitter {
const withKwargs =
argLength > 0 &&
typeof args[argLength - 1] === "object" &&
args[argLength - 1] !== null;
args[argLength - 1] !== null &&
args[argLength - 1]._rkwargs;
if (
name === "register" ||
name === "registerService" ||
Expand Down Expand Up @@ -877,7 +878,8 @@ export class RPC extends MessageEmitter {
const withKwargs =
argLength > 0 &&
typeof args[argLength - 1] === "object" &&
args[argLength - 1] !== null;
args[argLength - 1] !== null &&
args[argLength - 1]._rkwargs;
const transferables = args.__transferables__;
if (transferables) delete args.__transferables__;

Expand Down Expand Up @@ -911,7 +913,8 @@ export class RPC extends MessageEmitter {
const withKwargs =
argLength > 0 &&
typeof args[argLength - 1] === "object" &&
args[argLength - 1] !== null;
args[argLength - 1] !== null &&
args[argLength - 1]._rkwargs;
const transferables = args.__transferables__;
if (transferables) delete args.__transferables__;
return me._connection.emit(
Expand Down
2 changes: 1 addition & 1 deletion python/imjoy_rpc/VERSION
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"version": "0.3.32"
"version": "0.3.33"
}

0 comments on commit be36ef0

Please sign in to comment.