Gracefully scheduling the same runnable twice
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 72
- Forks
- 2
- Avg merge
- 6m
- Merged PRs (30d)
- 4
Description
Currently if the same runnable is scheduled twice it throws an error.
add(schedule, aFn, id('A'));
add(schedule, aFn, id('A'));
In imperative apps this probably isn't an issue, you just check to make sure you are scheduling the runnable once, but in dynamic apps like React this can be a real issue. Here are two scenarios where I think it is legitimate to handle this case more gracefully than an error:
- A user needs to reschedule a runnable. Here it would be ideal to get feedback that it is already scheduled and needs to be removed and readded instead of an error.
- A schedule call is part of a React component and is called each time a view instance is rendered even though it only needs to mount once.
(2) is relevant since a React component is intended to have all of its behavior and state included with the view. The scheduler, especially with a hook, allows for including global level behavior, usually to do with a simulation.
My proposed solution is to have add return a boolean where true is successfully adding and false is unsuccessful, meaning it was already in the system. Then this can be used as feedback for determining what to do next, either ignore or remove/add to reschedule.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the add scheduling entry point and trace how the scheduler handles a runnable that is already present, using the duplicated add(schedule, aFn, id('A')) example as the baseline. Define done as duplicate scheduling no longer throwing and the return value distinguishing a new addition from an already-scheduled runnable; inspect the existing test setup before adding coverage.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100