Skip to content

Commit

Permalink
Add sendBatch definition to @cloudflare/workers-types
Browse files Browse the repository at this point in the history
This commit adds relevant docstring to sendBatch method in Queues API,
which was previously not supported.
  • Loading branch information
mtlemilio committed Dec 14, 2022
1 parent ae0a516 commit 13b7493
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions types/defines/queues.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@ interface MessageBatch<Body = unknown> {
retryAll(): void;
}

/**
* A wrapper class used to structure message batches.
*/
type MessageSendRequest<Body = unknown> = {
/**
* The body of the message.
*/
body: Body
}

/**
* A binding that allows a producer to send messages to a Queue.
*/
Expand All @@ -44,4 +54,11 @@ interface Queue<Body = any> {
* @returns A promise that resolves when the message is confirmed to be written to disk.
*/
send(message: Body): Promise<void>;

/**
* Sends a batch of messages to the Queue.
* @param messages Each item in the array must be supported by the [structured clone algorithm](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm#supported_types). A batch can contain up to 100 messages, though items are limited to 128 KB each, and the total size of the array cannot exceed 256 KB.
* @returns A promise that resolves when the messages are confirmed to be written to disk.
*/
sendBatch(messages: Iterable<MessageSendRequest<Body>>): Promise<void>;
}

0 comments on commit 13b7493

Please sign in to comment.