Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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?

share|improve this question
    
The tag is wrong. I'd like to use the tag clock but it is new, and I'm not allowed to create new tags. –  zab Apr 28 at 15:38
1  
Related: (473), (1565) –  Mr.Wizard Apr 28 at 19:25

2 Answers 2

Use the Pause function:

SetAttributes[delayedFunction, {HoldFirst}];
delayedFunction[function_] := (Pause[5]; function);
share|improve this answer
    
More useful if defined as delayedFunction[function_, dt_] := (Pause[dt]; function) –  m_goldberg Apr 28 at 19:35

An alternative is to use the built in function, RunScheduledTask

Dynamic[z]
RunScheduledTask[z = 7, {5}]
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.