concurrency issues

C

Chris Smith

The Situation:

I've got a frameset that loads two other pages in frames. Frame A
creates an object, and the FrameB needs to invoke a method on that
object.

The Problem:

How does Frame B find out when Frame A has finished creating the object?
If Frame A hasn't finished creating the object yet, I want Frame B to
wait, and invoke the method as soon as the object has been created. I
can find out IF the object has been created (test the variable for
undefined or null), but if it hasn't been created yet, I can't find a
way to wait and send the notification when it has.

I've looked around, but JavaScript doesn't seem to provide the
synchronization constructs that I'd use to solve this problem in other
languages.

I have control over all three pages (the frameset, and both frames), and
I suspect the solution is going to have something to do with code in the
frameset, since neither frame can deterministically interact with the
other... but how does it get done? Without some way to manage
concurrency, I don't see a way to let the two share state.

--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 
C

Chris Smith

Andrew said:
Hi Chris, good - a nice clear description.

In frame B:
In a timed loop within Frame B, poll frame A every 200 milliseconds or so
to see if the object exists (actually poll each stage down the DOM tree to
catch if the frame exists etc, before directly testing for the object).
Only when you find the object do you leave the polling loop and invoke the
rest of your code. Note: You might want to put a limit on how long you poll
before you give up and err. You should also check that the method is
available on your object, rather than just assuming that once the object
exists that the method will as well. Something similar I think to some old
code I once wrote: http://www.andrewu.co.uk/clj/checkframesloaded/

Does the code at the end of this message look like what you were
suggesting? Do you see any problems with it?

Only when you find the object do you leave the polling loop and invoke the
rest of your code.

I assume by "the rest of your code", you mean the method I need to
invoke on the other frame? I certainly want the main frame to be
operational before the other frame finishes loading.
You should also check that the method is
available on your object, rather than just assuming that once the object
exists that the method will as well.

Okay, I've done so... but is there any reason this would ever happen?
I'm assigning the methods to the object in the constructor, and I would
think that the constructor would have to completely finish before the
reference returned from the object creation expression. I'm not very
familiar with JavaScript, and I'll do it the careful way until I know
for sure...

Anyhow, here's the code...

<script type="text/javascript">
var topDone = false;
var bottomDone = false;
var intervalKey = window.setInterval(function()
{
if (!topDone && parent && parent.topFrame
&& parent.topFrame.menu && parent.topFrame.menu.showPage)
{
parent.topFrame.menu.showPage('<%= pageName %>');
topDone = true;
}

if (!bottomDone && parent && parent.bottomFrame
&& parent.bottomFrame.menu && parent.bottomFrame.menu.showPage)
{
parent.bottomFrame.menu.showPage('<%= pageName %>');
bottomDone = true;
}

if (topDone && bottomDone)
{
window.clearInterval(intervalKey);
}
}, 200);
</script>

I'm a bit bothered by polling, even with the delay... but I guess it
can't be helped, then.

--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,149
Latest member
Vinay Kumar Nevatia0
Top