-
Notifications
You must be signed in to change notification settings - Fork 2
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.