0

I'm building a mobile app using Flutter, in which I use flutter_redux and redux_thunk. There's two kind of timed actions I want to achieve:

  1. Dispatch certain action every N seconds (repeated)

  2. Dispatch an action once after N seconds, likely from a thunk action (single run)

Are there any packages that wrap this logic? What would be your suggested way to achieve the two kind of scheduled actions?

Arno Moonen
  • 1,134
  • 2
  • 10
  • 28
  • Why not do `Timer.periodic(Duration(seconds: N), () => store.dispatch(action))`? For the non-periodic case, you could use a non-periodic `Timer` or `Future.delayed`. – jamesdlin May 03 '19 at 15:18
  • @jamesdlin I don't see a reason not to do it that way, I was just not sure if there would be other (perhaps better) ways to do it. If you can add it as an answer, I'm happy to accept it. – Arno Moonen May 07 '19 at 09:33

1 Answers1

1

I don't think there's anything special that you'd need to do specifically for Flutter Redux. In Dart, the general way to do periodic operations would be to use Timer.periodic:

Timer.periodic(Duration(seconds: N), () => store.dispatch(action));

For non-periodic operations, you could use a non-periodic Timer or use Future.delayed. (Timer gives you the ability to easily cancel it, but Future gives you a more direct way for the caller to specify how exceptions are handled.)

jamesdlin
  • 81,374
  • 13
  • 159
  • 204