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

  • 2
    $\begingroup$ Have you looked at RunScheduledTask and related functions? $\endgroup$
    – Heike
    Mar 30, 2012 at 16:04
  • $\begingroup$ Not till now :) Post this as answer and I'll mark it such! $\endgroup$
    – Reb.Cabin
    Mar 30, 2012 at 17:25
  • $\begingroup$ I've posted my answer. $\endgroup$
    – Heike
    Mar 30, 2012 at 20:15

1 Answer 1


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.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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