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'm experimenting with Inversion-of-Control (callback) programming patterns, and I would like a way to generate streams of data at specified real-time intervals. I came up with the illustrated way to use Animate (or Manipulate) to do it, and that's fine for experiments with the notebook front end, but I would like to have pure-code solutions I could put in a .m package. As always, I will be grateful for any hints, advice, and solutions!

enter image description here

share|improve this question
2  
Have you looked at RunScheduledTask and related functions? –  Heike Mar 30 '12 at 16:04
    
Not till now :) Post this as answer and I'll mark it such! –  Reb.Cabin Mar 30 '12 at 17:25
    
I've posted my answer. –  Heike Mar 30 '12 at 20:15

1 Answer 1

up vote 11 down vote accepted

You could use RunScheduledTask or its relatives for this. For example, to append a random integer to catch once every two seconds you could do something like

catch = {};
task = RunScheduledTask[AppendTo[catch, RandomInteger[10]], 2];

You could also use CreateScheduledTask which is similar to RunScheduledTask except that the task won't be started automatically after it's been created. You'll have to use StartScheduledTask to start it manually.

To start and stop the scheduled task you can use StartScheduledTask[task] and StopScheduledTask[task], respectively, and RemoveScheduledTask[task] will remove the scheduled task once you're done with it.

Additional information about these functions is available in the Documentation Center.

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.