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

feat: handlers abstraction + queue #10

Merged
merged 7 commits into from
Mar 22, 2024

Conversation

paoloricciuti
Copy link
Collaborator

@paoloricciuti paoloricciuti commented Mar 8, 2024

Making this pr so that we can evaluate if we like this abstraction to create handlers...i've implemented the default one and enqueue.

I'm open to name critiques and also general discussion on the approach. Basically we just have an object with all the handlers and every handler is a factory handler (so that it can have internal state like the queue or stuff like that).

For the moment i've passed the promise and the abort controller to the actual runner so that inside it it can await the promise to make sure the task instance finished running or stop it (we will need it for the restartable)

EDIT: i've also added the automatic creation of a series of shorthands. Basically whenever you add a new handler you will be able to create that handler like this

task(async ()=>{},{kind: "handler"});

AND like this

task.handler(async ()=>{});

all of this with typesafety...so if the handler accept some prop (like {max:number} for enqueue) you will get intellisense for both cases

eg:

task(async ()=>{},{kind: "enqueue", max: 2});

AND like this

task.enqueue(async ()=>{}, {max: 2});

personally i think it's a nice api and abstraction but eager to see what you think about it.

@paoloricciuti paoloricciuti added the enhancement New feature or request label Mar 22, 2024
@paoloricciuti paoloricciuti merged commit 6e9ed49 into main Mar 22, 2024
2 checks passed
@paoloricciuti paoloricciuti deleted the handlers-abstraction-and-enqueue branch March 22, 2024 12:00
@github-actions github-actions bot mentioned this pull request Mar 22, 2024
@beerinho beerinho mentioned this pull request Mar 22, 2024
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.

1 participant