Skip to content

Commit 89a6e1b

Browse files
committed
fix: add batching
1 parent 31bb8e3 commit 89a6e1b

File tree

3 files changed

+135
-117
lines changed

3 files changed

+135
-117
lines changed

templates/typescript/static/_package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,16 @@
1313
"author": "",
1414
"license": "Apache-2.0",
1515
"dependencies": {
16-
"@open-rpc/client-js": "^1.0.1",
16+
"@open-rpc/client-js": "^1.1.0",
1717
"@open-rpc/meta-schema": "^1.3.1",
1818
"@open-rpc/schema-utils-js": "^1.10.2",
19-
"lodash": "4.17.11"
19+
"lodash": "^4.17.15"
2020
},
2121
"devDependencies": {
22-
"typescript": "^3.2.4",
23-
"@types/ws": "^6.0.1",
2422
"@types/json-schema": "7.0.3",
23+
"@types/ws": "^6.0.1",
2524
"tslint": "^5.13.1",
26-
"typedoc": "^0.14.2"
25+
"typedoc": "^0.15.0",
26+
"typescript": "^3.2.4"
2727
}
2828
}

templates/typescript/static/package-lock.json

Lines changed: 96 additions & 111 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

templates/typescript/templated/exported-class.template.ts

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export class <%= className %> {
2929
if (options.transport === undefined || options.transport.type === undefined) {
3030
throw new Error("Invalid constructor params");
3131
}
32-
const {type, host, port} = options.transport;
32+
const {type, host, port} = options.transport;
3333
let path = options.transport.path || "";
3434
if(path && path[0] !== "/") {
3535
path = "/" + path;
@@ -51,6 +51,39 @@ export class <%= className %> {
5151
this.validator = new MethodCallValidator(this.openrpcDocument);
5252
}
5353
54+
/**
55+
* Initiates [[<%= className %>.startBatch]] in order to build a batch call.
56+
*
57+
* Subsequent calls to [[<%= className %>.request]] will be added to the batch.
58+
* Once [[<%= className %>.stopBatch]] is called, the promises for the [[<%= className %>.request]]
59+
* will then be resolved. If there is already a batch in progress this method is a noop.
60+
*
61+
* @example
62+
* myClient.startBatch();
63+
* myClient.foo().then(() => console.log("foobar"))
64+
* myClient.bar().then(() => console.log("foobarbaz"))
65+
* myClient.stopBatch();
66+
*/
67+
public startBatch(): void {
68+
return this.rpc.startBatch();
69+
}
70+
71+
/**
72+
* Initiates [[Client.stopBatch]] in order to finalize and send the batch to the underlying transport.
73+
*
74+
* stopBatch will send the [[<%= className %>]] calls made since the last [[<%= className %>.startBatch]] call. For
75+
* that reason, [[<%= className %>.startBatch]] MUST be called before [[<%= className %>.stopBatch]].
76+
*
77+
* @example
78+
* myClient.startBatch();
79+
* myClient.foo().then(() => console.log("foobar"))
80+
* myClient.bar().then(() => console.log("foobarbaz"))
81+
* myClient.stopBatch();
82+
*/
83+
public stopBatch(): void {
84+
return this.rpc.stopBatch();
85+
}
86+
5487
private request(methodName: string, params: any[]): Promise<any> {
5588
const methodObject = _.find(this.openrpcDocument.methods, ({name}) => name === methodName) as MethodObject;
5689
const openRpcMethodValidationErrors = this.validator.validate(methodName, params);

0 commit comments

Comments
 (0)