# How to generate a real-time stream of data?

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!

-
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

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.

-