2

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?

Kuba
  • 136,707
  • 13
  • 279
  • 740
zab
  • 275
  • 1
  • 8

2 Answers2

6

Use the Pause function:

SetAttributes[delayedFunction, {HoldFirst}];
delayedFunction[function_] := (Pause[5]; function);
3

An alternative is to use the built in function, RunScheduledTask

Dynamic[z]
RunScheduledTask[z = 7, {5}]
image_doctor
  • 10,234
  • 23
  • 40