473,396 Members | 2,050 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Asyncronous javascript component or thread emulation?

Hi.

I'm working on a project where a javascript program will get into
the middle of some very complicated operation and then decide
it needs to use to download an xml file from a server.

Because it's in the middle of something potentially complicated
I need to down the file synchronously
(without interrupting the flow of control), but I'd like
to make sure that the browser doesn't freeze up.

In another programming environment I would run the javascript
component in a thread -- is there any portable and safe way to
emulate this in javascript on recent browsers? My initial research
seems to say "no" but I'm not sure if I'm looking at up to date
information.

Please inform. Thanks! -- Aaron Watters

===

Horse: the other red meat.

Nov 29 '05 #1
4 2112
aa***************@yahoo.com wrote:
Because it's in the middle of something potentially complicated
I need to down the file synchronously (without interrupting the
flow of control), but I'd like to make sure that the browser doesn't
freeze up.
I do not think it is possible to resolve that contradiction.
You have to decide what is more important to your task.
In another programming environment I would run the javascript
component in a thread -- is there any portable and safe way to
emulate this in javascript on recent browsers?


No, ECMAScript implementations like JavaScript 1.5+ (Mozilla/5.0)
and JScript 5.5+ (IE/5.5+) are single-threaded.
PointedEars
Nov 29 '05 #2

aa***************@yahoo.com wrote:
Hi.

I'm working on a project where a javascript program will get into
the middle of some very complicated operation and then decide
it needs to use to download an xml file from a server.

Because it's in the middle of something potentially complicated
I need to down the file synchronously
(without interrupting the flow of control), but I'd like
to make sure that the browser doesn't freeze up.

[snip]

There are only two hacks I can think of which might help:-

1. If you are using the HTTPRequest object to download the XML file,
this can be set to synchronous or asynchronous (i.e. the function that
called the HTTPRequest can still keep running) download.

2. You could spawn a pop-up window/modeless dialogue box or
IFRAME(?) to do the download, as these are in some implementations
effectively a separate thread.

For instance, I use a pop-up window to provide a progress bar for a
function in the parent window. The parent window function can send an
update to the pop-up window without interrupting the parent window
function.

Regards

Julian Turner

Nov 30 '05 #3
VK

aa***************@yahoo.com wrote:
Because it's in the middle of something potentially complicated
I need to down the file synchronously
(without interrupting the flow of control), but I'd like
to make sure that the browser doesn't freeze up.


These are mutually exceptive requirements: the whole idea of
synchronized method (not in JavaScript only) is that the program flow
doesn't proceed until the method has returned the result. A
synchronized method that allows the sequent statements executions w/o
waiting for results is a non-sense (it is not synchronized then).

What you really want I guess is to prevent data access until new data
is ready. This is usually achieved by setting and checking flags.

Pseudo-code:

if (data update needed) {
glbFlagDataState = 'updating';
make XMLHttpRequest with callback function itsDone;
}

function itsDone() {
glbFlagDataState = 'ready';
}

function usingData() {
if (glbFlagDataState == 'ready') {
// do what you want
}
else {
// try your luck on the next system tick:
setTimeout(usingData);
}
}

Nov 30 '05 #4
On 2005-11-29, aa***************@yahoo.com <aa***************@yahoo.com> wrote:
Because it's in the middle of something potentially complicated
I need to down the file synchronously
(without interrupting the flow of control), but I'd like
to make sure that the browser doesn't freeze up.
install an infinite bandwidth connection between the cient machine and the
server. :) , live with the delay, or figure out how to do it asynchronously.
In another programming environment I would run the javascript
component in a thread -- is there any portable and safe way to
emulate this in javascript on recent browsers?


possibly.

Bye.
Jasen
Dec 1 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Jose Michael Meo R. Barrido | last post by:
I'm looking for a .net framework component to read write to Serial(Com port) that supports ANSI Emulation.
0
by: Andrés Joaquín | last post by:
Hello, I have a problem with a TCP Asyncronous Server Implementation. I take the solution from the Microsoft Site (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/ht...
1
by: Nathan | last post by:
On my .NET web project I am trying to make an asyncronous call to a function using IAsyncResult. The function will process for about a 1/2 hour. before it completes, the process abruptly ends as...
136
by: Matt Kruse | last post by:
http://www.JavascriptToolbox.com/bestpractices/ I started writing this up as a guide for some people who were looking for general tips on how to do things the 'right way' with Javascript. Their...
1
by: Allan Ebdrup | last post by:
I'm inside a function where I have a static cache, when the cache needs to be updated I want to do it asyncronously, because updating the cache takes a while. I want to use thread safety when...
104
by: Leszek | last post by:
Hi. Is it possible in javascript to operate on an array without knowing how mamy elements it has? What i want to do is sending an array to a script, and this script should add all values from...
2
by: Murali | last post by:
Hi friends, in Javascript without using Microsoft.XMLHTTP how can i do Asyncronous operation ? any experts pls bye
7
by: Marina Levit [MVP] | last post by:
Does anyone knows if this exists? Basically, a way to tell a method to execute, but a certain amount of time after the current event chain is finished - not immediately. With setTimeout, even if it...
3
by: OJ | last post by:
Hi, I have written a small C# 2.0 DLL which acts as a client to a Socket based server over the internet. I have written both synchronous and asynchronous methods to connect, send, and receive data...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.