@@ -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