Do not forget that these are two different things. Timer can be used anywhere for many purposes. It can be used on the client side to wait for the layout, for example, before running more code. Thus, this may have nothing to do with futures. I sometimes use a timer in client code to wait for a layout.
Timer is a general class for delaying the execution of some code. It doesn't matter if it has anything to do with futures or not. Another example would be client-side animation. It has nothing to do with futures or data asynchrony.
Futures, however, are mones that help you program asynchronous programs. Basically a replacement for passing simple callback functions.
Use new Future.of() when writing asynchronous programs, and this is appropriate for your situation (the same thing happens with new Future.immediate() .
Use the Timer class if you want to delay the execution of some code.
If you want to use futures for asynchronous programming and at the same time delay code, forget about the timer class if you do not need a real delay (more than 0 / next event).
source share