Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add sendBatch definition to @cloudflare/workers-types #223

Merged
merged 2 commits into from
Dec 14, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
mtlemilio marked this conversation as resolved.
Show resolved Hide resolved
* @returns A promise that resolves when the messages are confirmed to be written to disk.
*/
sendBatch(messages: Iterable<MessageSendRequest<Body>>): Promise<void>;
}