I'd like to write a function that delays the evaluation of a function (say) $5$ seconds after I hit Shift+Return. Is this possible?
Asked
Active
Viewed 239 times
2
2 Answers
6
Use the Pause function:
SetAttributes[delayedFunction, {HoldFirst}];
delayedFunction[function_] := (Pause[5]; function);
Hassler Thurston
- 136
- 3
-
More useful if defined as
delayedFunction[function_, dt_] := (Pause[dt]; function)– m_goldberg Apr 28 '14 at 19:35
3
An alternative is to use the built in function, RunScheduledTask
Dynamic[z]
RunScheduledTask[z = 7, {5}]
image_doctor
- 10,234
- 23
- 40
clockbut it is new, and I'm not allowed to create new tags. – zab Apr 28 '14 at 15:38