473,795 Members | 3,428 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2133
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) {
glbFlagDataStat e = 'updating';
make XMLHttpRequest with callback function itsDone;
}

function itsDone() {
glbFlagDataStat e = 'ready';
}

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

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
1258
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
1103
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 ml/cpconnon-blockingserversocketexample.asp) and implemented it but when i test it I get problems... I used the below test client code to test the Syncronous Server but after a
1
1220
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 though it has timed out. I'm not sure what is timing out. Would it be the page I am making the async call from? Or possibly the connection/command objects I am using to connect to my sql db?
136
9460
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 code was littered with document.all and eval, for example, and I wanted to create a practical list of best practices that they could easily put to use. The above URL is version 1.0 (draft) that resulted. IMO, it is not a replacement for the FAQ,...
1
2191
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 writing and reading the cache (a Mutex?) Private Function Count(ByVal Guid)As Int32 Static Dim countResults As Hashtable = New Hashtable Static Dim countResultTimestamps As Hashtable = New Hashtable 'Here I want to call...
104
17016
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 that array Could you show me a little example how to do this? Thanks.
2
1373
by: Murali | last post by:
Hi friends, in Javascript without using Microsoft.XMLHTTP how can i do Asyncronous operation ? any experts pls bye
7
2097
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 says to execute in a second, that is really a second after the entire call chain is finished. So if the call chain happens to take 10 seconds to complete - the setTimeout method will execute in 11 seconds. Timers just execute at regular...
3
1732
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 from the server. Each request/response can take upto 180 seconds. I am trying to use the asyncronous calls in an ASP.NET C# 2.0 Webcontrol, which displays the returned data. At the moment I am happily using the asyncronous functions and events...
0
9519
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10437
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10214
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10164
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9042
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6780
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5437
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5563
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.