Skip to content

Commit

Permalink
Merge branch 'release/v0.20.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
holtwick committed Apr 9, 2024
2 parents c5f3294 + 04c628a commit 1359dad
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "zeed",
"type": "module",
"version": "0.20.1",
"version": "0.20.2",
"description": "🌱 Simple foundation library",
"author": {
"name": "Dirk Holtwick",
Expand Down Expand Up @@ -65,14 +65,14 @@
"watch": "nr build -- --watch src"
},
"devDependencies": {
"@antfu/eslint-config": "^2.12.2",
"@antfu/eslint-config": "^2.13.0",
"@antfu/ni": "^0.21.12",
"@types/node": "^20.12.5",
"@types/node": "^20.12.6",
"@vitest/coverage-v8": "^1.4.0",
"esbuild": "^0.20.2",
"eslint": "^9.0.0",
"tsup": "^8.0.2",
"typedoc": "^0.25.12",
"typedoc": "^0.25.13",
"typescript": "^5.4.4",
"vite": "^5.2.8",
"vitest": "^1.4.0"
Expand Down
26 changes: 17 additions & 9 deletions src/common/msg/rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ export interface RPCOptionsBasic extends Pipe {
onError?: (error: Error, functionName: string, args: any[]) => boolean | void
/** Custom error handler for timeouts */
onTimeoutError?: (functionName: string, args: any[]) => boolean | void
/** Throw execptions. Default: true */
exceptions?: boolean
}

export interface RPCOptions<Remote> extends RPCOptionsBasic {
Expand Down Expand Up @@ -68,6 +70,7 @@ function setupRPCBasic(options: RPCOptionsBasic, functions: any, eventNames: str
onError,
onTimeoutError,
onlyEvents = false,
exceptions = true,
} = options

const rpcPromiseMap = new Map<number, {
Expand Down Expand Up @@ -111,7 +114,7 @@ function setupRPCBasic(options: RPCOptionsBasic, functions: any, eventNames: str
const promise = rpcPromiseMap.get(id)
if (promise != null) {
clearTimeout(promise.timeoutId)
if (mode === RPCMode.reject)
if (mode === RPCMode.reject && exceptions === true)
promise.reject(method)
else
promise.resolve(method)
Expand Down Expand Up @@ -146,7 +149,10 @@ function setupRPCBasic(options: RPCOptionsBasic, functions: any, eventNames: str
throw new Error(`rpc timeout on calling "${method}"`)
}
catch (e) {
reject(e)
if (exceptions === true)
reject(e)
else
resolve(undefined)
}
rpcPromiseMap.delete(id)
}, timeout).unref?.()
Expand Down Expand Up @@ -200,10 +206,12 @@ export function useRPCHub(options: RPCOptionsBasic) {
export type UseRPCHubType = ReturnType<typeof useRPCHub>

// Syntax test case
// const hub: UseRPCHubType = {} as any
// const x = hub({
// test(name: string): string {
// return name
// },
// })
// await x.test('dsd')
// async function _demo() {
// const hub: UseRPCHubType = {} as any
// const x = hub({
// test(name: string): string {
// return name
// },
// })
// await x.test('dsd')
// }

0 comments on commit 1359dad

Please sign in to comment.