You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+39Lines changed: 39 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -899,6 +899,45 @@ main();
899
899
900
900
```
901
901

902
+
903
+
## Specifications
904
+
905
+
### Throwing Timeouts
906
+
907
+
By default, a timeout will not cause an RPC call to automatically throw, this must be manually done by the handler when it receives the abort signal from `ctx.signal`. An example of this is like so:
908
+
909
+
```ts
910
+
classTestMethodextendsUnaryHandler {
911
+
public handle =async (
912
+
input:JSONValue,
913
+
cancel: (reason?:any) =>void,
914
+
meta:Record<string, JSONValue> |undefined,
915
+
ctx:ContextTimed,
916
+
): Promise<JSONValue> => {
917
+
const abortProm =utils.promise<never>();
918
+
ctx.signal.addEventListener('abort', () => {
919
+
resolveCtxP(ctx);
920
+
abortProm.resolveP(ctx.signal.reason);
921
+
});
922
+
throwawaitabortProm.p;
923
+
};
924
+
}
925
+
```
926
+
927
+
### Timeout Middleware
928
+
929
+
The `timeoutMiddleware` sets an RPCServer's timeout based on the lowest timeout between the Client and the Server. This is so that handlers can eagerly time out and stop processing as soon as it is known that the client has timed out.
930
+
931
+
This case can be seen in the first diagram, where the server is able to stop the processing of the handler, and close the associated stream of the RPC call based on the shorter timeout sent by the client:
932
+
933
+

934
+
935
+
Where the `RPCClient` sends a timeout that is longer than that set on the `RPCServer`, it will be rejected. This is as the timeout of the client should never be expected to exceed that of the server, so that the server's timeout is an absolute limit.
936
+
937
+

938
+
939
+
The `timeoutMiddleware` is enabled by default, and uses the `.metadata.timeout` property on a JSON-RPC request object for the client to send it's timeout.
940
+
902
941
## Development
903
942
904
943
Run `nix-shell`, and once you're inside, you can use:
0 commit comments