B
bwucke
Short: One window writes to <input>, the other reads the same <input>.
Is it a race condition or are the reads/writes atomic?
Long: My app has an option to print results in a nicely formatted,
print-friendly way. The main window is loaded with options, textboxes,
buttons, has some graphics etc, nice as an app but not really
printable, so clicking "print" icon opens a new window with the page
with a nicely formatted, print-friendly summary, some comment entry
textareas and tools for printing (whatever unnecessary on printout,
hidden through @media print{} stylesheets.) The app window, on any
value change fills in a hidden input field. The print window
periodically (every 2s) loads the input field and introduces changes to
itself if necessary. My code sniplets below. The question is: Am I too
paranoid, or will it -just work- or it won't work despite me being
paranoid? Other comments? Any way to do it better? For now the code
works, but you never know what bugs lurk in the IPC.
--app window--
function update() // called on any change to any value in the form
when the user types.
{
....
document.f.comm.value=val1+"!"+val2+"!"+fieldx+"!".... etc.
}
--print window--
var datastring='';
var dataarr= new Array();
function initdoc() // called from <body onload="">
{
....
setInterval(pickdata,2000);
}
function pickdata()
{
if(datastring==opener.document.f.comm.value) return; // data
unchanged, no need to update
do {
datastring=opener.document.f.comm.value;
// if changed since previous read, likely broken, reread. Paranoia?
} while(datastring==opener.document.f.comm.value);
dataarr=String(datastring).split('!');
....
}
Is it a race condition or are the reads/writes atomic?
Long: My app has an option to print results in a nicely formatted,
print-friendly way. The main window is loaded with options, textboxes,
buttons, has some graphics etc, nice as an app but not really
printable, so clicking "print" icon opens a new window with the page
with a nicely formatted, print-friendly summary, some comment entry
textareas and tools for printing (whatever unnecessary on printout,
hidden through @media print{} stylesheets.) The app window, on any
value change fills in a hidden input field. The print window
periodically (every 2s) loads the input field and introduces changes to
itself if necessary. My code sniplets below. The question is: Am I too
paranoid, or will it -just work- or it won't work despite me being
paranoid? Other comments? Any way to do it better? For now the code
works, but you never know what bugs lurk in the IPC.
--app window--
function update() // called on any change to any value in the form
when the user types.
{
....
document.f.comm.value=val1+"!"+val2+"!"+fieldx+"!".... etc.
}
--print window--
var datastring='';
var dataarr= new Array();
function initdoc() // called from <body onload="">
{
....
setInterval(pickdata,2000);
}
function pickdata()
{
if(datastring==opener.document.f.comm.value) return; // data
unchanged, no need to update
do {
datastring=opener.document.f.comm.value;
// if changed since previous read, likely broken, reread. Paranoia?
} while(datastring==opener.document.f.comm.value);
dataarr=String(datastring).split('!');
....
}