Skip to content

Conversation

Brayden
Copy link
Collaborator

@Brayden Brayden commented Jul 8, 2025

Add first party support for queuing function calls to be ran sequentially.

You can add multiple function calls with parameters into the queue with this.queue.enqueue within an Actor class and it will automatically append that to the end of our operation queue to be executed. Below is an example usage.

export class MyQueueActor extends Actor<Env> {
    async fetch(request: Request): Promise<Response> {
        this.queue.enqueue('operationA', []);
        this.queue.enqueue('operationB', []);
        return new Response('Operations queued')
    }

    public async operationA(payload: any): Promise<number> {
        // Wait for 5 seconds before returning
        await new Promise(resolve => setTimeout(resolve, 5000));
        console.log('Operation A completing')
        return 1;
    }

    public async operationB(payload: any): Promise<number> {
        await new Promise(resolve => setTimeout(resolve, 10000));
        console.log('Operation B completing')
        return 2;
    }
}
export default handler(MyQueueActor);

@Brayden Brayden self-assigned this Jul 8, 2025
@Brayden Brayden added the enhancement New feature or request label Jul 8, 2025
@khanhicetea
Copy link

Nice, it works better for tracking DO instance, queue then master DO can consume

@khanhicetea
Copy link

Ohh, I mistake reading, this is actor queue internal, not CF queue product :) Sorry

@cortopy
Copy link

cortopy commented Jul 12, 2025

I love this! I was thinking of building something similar because I need my tasks to persist rather than be deleted within an event source context for a DO. This is something I can't do with CF Queues (the product).

Would it it possible to have a toggle so that this.dequeue doesn't get called on success?

@Brayden
Copy link
Collaborator Author

Brayden commented Jul 17, 2025

I love this! I was thinking of building something similar because I need my tasks to persist rather than be deleted within an event source context for a DO. This is something I can't do with CF Queues (the product).

Would it it possible to have a toggle so that this.dequeue doesn't get called on success?

Anything is possible! What's the use case to solve by not dequeuing the operation on success?

@cortopy
Copy link

cortopy commented Jul 18, 2025

My main use case would to replay aggregate events for new subscribers. I know this is a queue, but now that pubsub has been closed at Cloudflare I thought it’d be great if this library could support both queue and event streaming use cases

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants