1

A JavaScript function called jsReceiveRawAudioDataFromFlash(rawData) is called almost every 100 ms, depending on how fast the microphone in Flash collects audio data.

function jsReceiveRawAudioDataFromFlash(rawData) {
    document.write("Beginning of this JS function");

    // Computation expensive work
    // I CANNOT put this work in Flash, must be in JavaScript

    // Send it to the network (server)

    document.write("Beginning of this JS function");
}

Every time the Flash microphone collects a fragment of audio data, it will call this JavaScript function.

This JS function receives the rawData, and does some very computation expensive work, and then sends out to the network (server).

I found that, the previous call has NOT be finished, another call is started, and then the un-executed part of the previous call is dropped off. EDIT - (I had a memory issue within this function, after I fixed it, it does not get dropped off)

So I need to schedule the call. How could I do it?

Thanks.

Peter

Peter Lee
  • 12,931
  • 11
  • 73
  • 100
  • "Dropped" how? JS does not simply drop the execution of a function. Do you happen to be modifying global variables from the function? – bfavaretto Mar 03 '12 at 02:39
  • @bfavaretto, yes, it does modify a global AudioStream that receives raw audio data and encodes it. – Peter Lee Mar 05 '12 at 17:18
  • @bfavaretto, I had memory issue within that function. After I fixed that, it does not get dropped. – Peter Lee Mar 09 '12 at 00:08
  • Great! So you probably won't even need to schedule calls to that function, right? But if you do, take a look at jQuery's `queue` and `dequeue` methods. – bfavaretto Mar 09 '12 at 14:49

1 Answers1

1

Add an array into your JavaScript and a boolean to say that the function is operating/running.

When the function is called, check if the function is already running, and if it is, stack the data to be executed into the array.

When the function finishes, check the array for any further items to be operated on. If there are any, operate on them, if not, set the boolean to false and it waits.

Something akin to this?

MyStream
  • 2,533
  • 1
  • 16
  • 33
  • thanks for your reply. Is there a library that already does this? – Peter Lee Mar 05 '12 at 17:19
  • I found this: http://mootools.net/docs/core125/core/Class/Class.Extras . I'm not sure if this one meets what I want. – Peter Lee Mar 05 '12 at 17:37
  • I'm not aware of a specific library for it, but if you can try to restructure your code with that logic, perhaps we can help you refine it? – MyStream Mar 05 '12 at 18:56
  • jQuery has queueing/dequeueing methods, see [this answer](http://stackoverflow.com/a/3314877/825789). – bfavaretto Mar 05 '12 at 19:38