473,399 Members | 2,774 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,399 software developers and data experts.

Not sleep, but at least be able to dispatch events

After reading the many posts on the newsgroup,
I still disagree with the people who claim you
will never need a sleep(), or that a sleep()
is a bad idea, or that sleep() does not fit
in the event driven model, etc..

Fine, not sleep, but at least a blocking
function - that's whats missing in javascript,
and I bet that's what's most people looking for
sleep() had wanted.

A blocking function (like a wait() that
others have proposed) would dispatch events
but not proceed the script. Terrible idea? That's
what a prompt() or an alert() does, they block
the execution of the script while servicing
events and waiting for user inputs... but
a "wait()" like function will have custom
logic to get out of the loop instead of waiting
for a button click.

Why would I want to do this? Can't I do it with
setTimeout()? No. Consider I want to write a
reusable function that someone can just pick
up and use it:

function foohelper() {
// essentially the second part of foo
}

function foo() {
...
setTimeout('foohelper();');
}

The caller should be able to expect foo() to be
atomic and never interleaved with their code (bar)

foo();
bar();

Whenever I discuss this with others, the repsonse
that invariably comes back is "What are you trying to
do?" "Why would you care" (good indication that they
have no idea how to solve this). It's simple, I want
a function others can call and not having
1. me to worry about what others will do and
2. others worrying about what I have done.
What if foo() sets up some shared object that bar uses?
Say foo() loads an applet that creates a a window that
covers up the screen to act as some new wallpaper
background before bar() loads an applet that
puts up a dialog... if the order is reversed (that happens
when foo loads the applet dynamically), bar()'s
dialog is covered up by foo()'s... the thing is, I
should be able to, within foo(), block the execution
of the script by polling until my applet has fully
initialized... you may propose "why don't you load your
applet at <body onload=>" or "put bar() at a setTimeout"..
and if you do ask that, let me reiterate my point - that
I should not care how other people use my function, that
other people should be able to call it inline, call
in at onload, call it by doing a document.write('foo();')
or whatever which way, and it still works. Javascript
disallows that. That's why people want a sleep() (or a sleep
like function in fact, not exactly a thread blocking sleep()).

If you have actually read the whole thing (reasonably
carefully) and can come up with a solution (yes, I am aware
that you potentially have a wait() called by a wait() recursively,
but that's not a problem and why so is another topic) thanks,
I'd like to know about it, and yeah, I'll take back everything
I've just said :) If not, thank you for agreeing with me :)

May 15 '06 #1
2 2568
fl****@yahoo.com wrote:
A blocking function (like a wait() that
others have proposed) would dispatch events
but not proceed the script. Terrible idea? That's
what a prompt() or an alert() does, they block
the execution of the script while servicing
events and waiting for user inputs... but
a "wait()" like function will have custom
logic to get out of the loop instead of waiting
for a button click. .... If you have actually read the whole thing (reasonably
carefully) and can come up with a solution (yes, I am aware
that you potentially have a wait() called by a wait() recursively,
but that's not a problem and why so is another topic) thanks,
I'd like to know about it, and yeah, I'll take back everything
I've just said :) If not, thank you for agreeing with me :)


I found the first post from Robin P interesting, which shows a
window.showModalDialog approach:
http://groups.google.com/group/micro...b5be821910c3d/
Perhaps get IE7 and file a bug report

Csaba Gabor from Vienna

May 15 '06 #2
Csaba Gabor,

Interesting, too bad this showmodaldialog solution wont work with popup
blockers

But it does reinforce my point - contrary to what people insisted on,
a "sleep" is imperative in javascript, and is missing

May 16 '06 #3

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

Similar topics

21
by: Alo Sarv | last post by:
Hi From what I have understood from various posts in this newsgroup, writing event loops pretty much comes down to this: while (true) { handleEvents(); sleep(1); // or _sleep() or...
9
by: Chris Dunaway | last post by:
According to the docs, calling Thread.Sleep(0) causes the thread to be "suspended to allow other waiting threads to execute." What happens if I call Thread.Sleep(500)? Do other threads not get a...
14
by: Joe | last post by:
Does anyone know the difference, in practical terms, between Thread.Sleep (10000) and Thread.CurrentThread.Join (10000)?? The MSDN says that with Join, standard COM and SendMessage pumping...
3
by: Aleksandar Cikota | last post by:
Hi all, Does a async sleep exist? How to check this every 10 sec, but that the CPU is free? Code: import win32com.client import time import os
17
by: OlafMeding | last post by:
Below are 2 files that isolate the problem. Note, both programs hang (stop responding) with hyper-threading turned on (a BIOS setting), but work as expected with hyper-threading turned off. ...
4
by: Helge Jensen | last post by:
In C# 2.0 System.IO.Stream is declared as: public class Stream: ..., IDisposable { ... public void Dispose(); public void Dispose(bool); IDisposable.Dispose(); } Which must be a...
7
by: multicherry | last post by:
Hi, Having searched for a way to fetch a window object by name, all I came across were answers along the line of... "All you have to do is say windowObj = window.open("blah", "name");" which...
11
by: mark | last post by:
Right now I have a thread that sleeps for sometime and check if an event has happened and go back to sleep. Now instead I want the thread to sleep until the event has occured process the event and...
5
by: greg | last post by:
sokol wrote: The sched module is *not* designed for multithreading. It assumes that the thread waiting for events is the only one putting events into the queue, so it's impossible for an...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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...
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.