Skip to content

Commit

Permalink
fix: add more docs
Browse files Browse the repository at this point in the history
  • Loading branch information
BelfordZ committed Jul 25, 2019
1 parent 46e8eec commit 7423e52
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 9 deletions.
3 changes: 3 additions & 0 deletions src/RequestManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ class RequestManager {
}

/**
* Begins a batch call by setting the [[RequestManager.batchStarted]] flag to `true`.
*
* [[RequestManager.batch]] is a singleton - only one batch can exist at a given time, per [[RequestManager]].
*
*/
public startBatch(): void {
Expand Down
34 changes: 25 additions & 9 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,35 +21,51 @@ interface IClient {
* ```
*
*/

class Client implements IClient {
public requestManager: RequestManager;
constructor(requestManager: RequestManager) {
this.requestManager = requestManager;
}

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

/**
* Ends a JSON-RPC Batch call. This client will batch requests from when startBatch
* was called until endBatch. This REQUIRES startBatch to be called first.
* Initiates [[RequestManager.endBatch]] in order to finalize and send the batch to the underlying transport.
*
* [[Client.endBatch]] will send the [[Client.request]] calls made since the last [[Client.startBatch]] call. For that
* reason, [[Client.startBatch]] MUST be called before [[Client.endBatch]].
*
* @example
* myClient.startBatch();
* myClient.request("foo", ["bar"]).then(() => console.log('foobar'));
* myClient.request("foo", ["baz"]).then(() => console.log('foobaz'));
* myClient.endBatch();
*/
public endBatch(): void {
return this.requestManager.endBatch();
}

/**
* A JSON-RPC call is represented by sending a Request object to a Server.
*
* @param method A String containing the name of the method to be invoked.
* Method names that begin with the word rpc followed by a
* period character (U+002E or ASCII 46) are reserved for rpc-internal
* methods and extensions and MUST NOT be used for anything else.
* @param method A String containing the name of the method to be invoked. Method names that begin with the word rpc
* followed by a period character (U+002E or ASCII 46) are reserved for rpc-internal methods and extensions and
* MUST NOT be used for anything else.
* @param params A Structured value that holds the parameter values to be used during the invocation of the method.
*/
public async request(method: string, params: any) {
Expand Down

0 comments on commit 7423e52

Please sign in to comment.