1

I'm using redux-saga in my react native application and I have some events which will happen at some point of time.
E.g.
ev0 - 01.01.2021, 08:00
ev1 - 01.01.2021, 15:00
ev2 - 02.01.2021, 09:00
etc.

There should be a saga which waits for next event and dispatches some actions and waits for the next event.

My first thought was to get the closest event time when app starts and wait for event0Time - timestampNow milliseconds in saga. After that, dispatch my actions and wait for event1Time - event0Time milliseconds and so on.

But I don'r really like this approach, it looks tricky.
So I wonder if there is a better way to achieve what I need.

Maybe a "best practice" or something...

shift66
  • 11,760
  • 13
  • 50
  • 83
  • The way you described (calculating the milliseconds then calling `delay`, probably in a loop) is how i'd do it. Can you be more specific about what you don't like about it? – Nicholas Tower Jan 28 '20 at 14:37
  • I don't think there is any API that would allow you to wait for exact time, so you will need to use something delay, resp. setTimeout. One way to improve the accuracy is to reset the timer every minute, see https://stackoverflow.com/questions/19088040/how-to-run-a-function-at-specific-time-date – Martin Kadlec Jan 28 '20 at 15:20

0 Answers0