Skip to content

Commit ae73d1a

Browse files
committed
Set allowNestedFunctions default to false, and added an option to suppress errors when a callback is missing.
1 parent 4a29d3b commit ae73d1a

4 files changed

Lines changed: 19 additions & 12 deletions

File tree

index.esm.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,10 @@ const recuCopy = (tree, mutable) => {
7474
*/
7575
const createIorpc = (sendFn, localApi = {}, {
7676
maxPendingResponses = 10000,
77-
allowNestedFunctions = true,
77+
allowNestedFunctions = false,
7878
exposeErrors = true,
79-
injectToThis = true
79+
injectToThis = true,
80+
ignoreCallbackUnavailable = false
8081
}) => {
8182
const clbs = {};
8283
let trimWarningFired = false;
@@ -278,6 +279,7 @@ const createIorpc = (sendFn, localApi = {}, {
278279
if (isNaN(message.apiFunc)) {
279280
errMsg = `Function '${message.apiFunc}' is not registered for the iorpc API. Please verify it is properly defined and exposed.`;
280281
} else {
282+
if (ignoreCallbackUnavailable) return;
281283
errMsg = `Callback '${message.apiFunc}' is unavailable. It might have been removed from the waiting queue (maxPendingResponses overflow) or via unbind().`;
282284
}
283285
const e = new Error(errMsg);

index.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,10 @@
7575
*/
7676
const createIorpc = (sendFn, localApi = {}, {
7777
maxPendingResponses = 10000,
78-
allowNestedFunctions = true,
78+
allowNestedFunctions = false,
7979
exposeErrors = true,
80-
injectToThis = true
80+
injectToThis = true,
81+
ignoreCallbackUnavailable = false
8182
}) => {
8283
const clbs = {};
8384
let trimWarningFired = false;
@@ -279,6 +280,7 @@
279280
if (isNaN(message.apiFunc)) {
280281
errMsg = `Function '${message.apiFunc}' is not registered for the iorpc API. Please verify it is properly defined and exposed.`;
281282
} else {
283+
if (ignoreCallbackUnavailable) return;
282284
errMsg = `Callback '${message.apiFunc}' is unavailable. It might have been removed from the waiting queue (maxPendingResponses overflow) or via unbind().`;
283285
}
284286
const e = new Error(errMsg);

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "iorpc",
3-
"version": "9.0.6",
3+
"version": "9.1.0",
44
"keywords": [
55
"rpc",
66
"callback",

readme.md

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -373,12 +373,14 @@ ws.on('open', async () => {
373373
}
374374
cbWithErr.unbind()
375375

376-
// The ability to pass function references within objects or arrays is implemented. Make sure to unbind them when they are no longer in use.
377-
const {fn1, fn2} = await remote.functionWithReturnOfTwoFn()
378-
console.log(await fn1()) // fn1
379-
console.log(await fn2()) // fn2
380-
fn1.unbind()
381-
fn2.unbind()
376+
if (false) { // works if allowNestedFunctions option is true
377+
// The ability to pass function references within objects or arrays is implemented. Make sure to unbind them when they are no longer in use.
378+
const {fn1, fn2} = await remote.functionWithReturnOfTwoFn()
379+
console.log(await fn1()) // fn1
380+
console.log(await fn2()) // fn2
381+
fn1.unbind()
382+
fn2.unbind()
383+
}
382384
const remoteClbsSize2 = await remote.clbsSize()
383385
console.log(remoteClbsSize2) // 0
384386
}, 3000)
@@ -411,9 +413,10 @@ It should accept a callback which will receive parsed message objects.
411413
`options?: Object` – Optional configuration parameters:
412414

413415
- `maxPendingResponses: number = 10000` – Maximum number of unresolved async calls allowed at once. Prevents overflow. It warns once about an error if the limit is exceeded, and deletes the oldest one used.
414-
- `allowNestedFunctions: boolean = true` – If true, allows functions to be nested in objects or arrays and passed remotely.
416+
- `allowNestedFunctions: boolean = false` – If true, allows functions to be nested in objects or arrays and passed remotely.
415417
- `exposeErrors: boolean = true` – If true, forwards full remote error details (like stack traces). If false, replaces them with a generic message.
416418
- `injectToThis: boolean = true` – If true, replaces this inside called functions with `this.remoteApi`.
419+
- `ignoreCallbackUnavailable: boolean = false` – If true, errors due to missing callbacks will be ignored. Useful when integrating multiple interfaces over a single channel.
417420

418421
`Return` - An object with the following properties:
419422
- `remote: Object` – A proxy object. Accessing `remote.someFunction()` will trigger a remote call to `someFunction` on the other side.

0 commit comments

Comments
 (0)