Skip to content

Commit 7423e52

Browse files
committed
fix: add more docs
1 parent 46e8eec commit 7423e52

File tree

2 files changed

+28
-9
lines changed

2 files changed

+28
-9
lines changed

src/RequestManager.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ class RequestManager {
8888
}
8989

9090
/**
91+
* Begins a batch call by setting the [[RequestManager.batchStarted]] flag to `true`.
92+
*
93+
* [[RequestManager.batch]] is a singleton - only one batch can exist at a given time, per [[RequestManager]].
9194
*
9295
*/
9396
public startBatch(): void {

src/index.ts

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,35 +21,51 @@ interface IClient {
2121
* ```
2222
*
2323
*/
24-
2524
class Client implements IClient {
2625
public requestManager: RequestManager;
2726
constructor(requestManager: RequestManager) {
2827
this.requestManager = requestManager;
2928
}
3029

3130
/**
32-
* Starts a JSON-RPC Batch call. The client will batch following requests.
33-
* This method REQUIRES endBatch be called when finished calling requests.
31+
* Initiates [[RequestManager.startBatch]] in order to build a batch call.
32+
*
33+
* Subsequent calls to [[Client.request]] will be added to the batch. Once endBatch is called, the promises for the
34+
* [[Client.request]] will then be resolved. If the request manager already has a batch in progress, this method
35+
* is a noop.
36+
*
37+
* @example
38+
* myClient.startBatch();
39+
* myClient.request("foo", ["bar"]).then(() => console.log('foobar'));
40+
* myClient.request("foo", ["baz"]).then(() => console.log('foobaz'));
41+
* myClient.endBatch();
3442
*/
3543
public startBatch(): void {
3644
return this.requestManager.startBatch();
3745
}
3846

3947
/**
40-
* Ends a JSON-RPC Batch call. This client will batch requests from when startBatch
41-
* was called until endBatch. This REQUIRES startBatch to be called first.
48+
* Initiates [[RequestManager.endBatch]] in order to finalize and send the batch to the underlying transport.
49+
*
50+
* [[Client.endBatch]] will send the [[Client.request]] calls made since the last [[Client.startBatch]] call. For that
51+
* reason, [[Client.startBatch]] MUST be called before [[Client.endBatch]].
52+
*
53+
* @example
54+
* myClient.startBatch();
55+
* myClient.request("foo", ["bar"]).then(() => console.log('foobar'));
56+
* myClient.request("foo", ["baz"]).then(() => console.log('foobaz'));
57+
* myClient.endBatch();
4258
*/
4359
public endBatch(): void {
4460
return this.requestManager.endBatch();
4561
}
62+
4663
/**
4764
* A JSON-RPC call is represented by sending a Request object to a Server.
4865
*
49-
* @param method A String containing the name of the method to be invoked.
50-
* Method names that begin with the word rpc followed by a
51-
* period character (U+002E or ASCII 46) are reserved for rpc-internal
52-
* methods and extensions and MUST NOT be used for anything else.
66+
* @param method A String containing the name of the method to be invoked. Method names that begin with the word rpc
67+
* followed by a period character (U+002E or ASCII 46) are reserved for rpc-internal methods and extensions and
68+
* MUST NOT be used for anything else.
5369
* @param params A Structured value that holds the parameter values to be used during the invocation of the method.
5470
*/
5571
public async request(method: string, params: any) {

0 commit comments

Comments
 (0)