Forum Moderators: open

Message Too Old, No Replies

Delaying setInterval's delay-function start execution

Is it possible?

         

dnimrodx

3:25 pm on Feb 6, 2004 (gmt 0)

10+ Year Member



Hi,

I hope you can help me on this. It is about

(set/clear)Interval
.

The problem is I have classes' objects being accessed and used by a wide diversity of functions throughout the entire code (also, different classes access and change eachother's contents). In the same way, some

setInterval
delay functions access and change (sometimes even deleting) classes' objects' contents. I need to prevent this from happening.

Well I need to somehow delay the execution of

setInterval'
loop function call, in order to prevent this: (take a look at this example)

X.theFunction()
{
[red][validate X.theobject here][/red]
[exists, continue with process]
[return]
}

Y.loopdelayFunction()
{
[red][if something, delete X.theobject][/red]
.
:
.
}

What I cannot have is
Y.loopdelayFunction
starting its execution after validation in
X.theFunction
occured as it will result in error after it had returned from the delay loop.

Is there a way of locking (or delaying should I say)

setInterval
's delay function start execution?

All comments are much appreciated,

Thank you, ;)

d#Nimrod

BTW: have been trying to find some information on the Net, but couldn't.

isitreal

6:12 pm on Feb 7, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You can use a boolean test, in javascript a variable declared outside of a function is global automatically, so you'll always have access to this anywhere on the page:

var b_do_delay = true;

X.theFunction()
{
[validate X.theobject here]
[exists, continue with process
b_do_delay = false;
]
[return]
}

Y.loopdelayFunction()
{
if ( b_do_delay )
{
[if something, delete X.theobject]
}
.
:
.
}

dnimrodx

9:49 pm on Feb 7, 2004 (gmt 0)

10+ Year Member



IsItReal,

That is precisely the way I have implemented it and I must say I am not happy with it as I consider it a form of a hack... ;)

I too do not think there is anyother possible way to achieve what I want.

But, hey, thanks for the input,

d#Nimrod

isitreal

10:53 pm on Feb 7, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I wouldn't call assigning a boolean completed variable a hack personally, it works really well, it's simple, clean, and easy to do, what else could you want from a technique? I use that all the time, usually to keep programs from running over and over after I assign static values to variables etc.

dnimrodx

5:29 pm on Feb 8, 2004 (gmt 0)

10+ Year Member



Yeah, I get your point. I think the problem is I sometimes forget I'm dealing with javascript. After all it is a scripting language.

Thanks isitreal :)

isitreal

10:28 pm on Feb 8, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Yeah, I think that's the point, I get lost in that sometimes too, scripting is supposed to be fast, easy, and above all reliable, so you can move onto something else, not having to worry about assigning and releasing memory etc, buffer overruns etc. What I try to do is find techniques that always work (especially with javascript, where you don't have very good control of the runtime environment, the browser that is). The more complex the code gets, the more likely it won't work on some browser or other, especially Safari/IE mac, early Mozillas, opera, etc. The simpler and more basic your techniques are, the more likely most browsers will support what you are trying to do. I've had the most utterly basic Javascript fail on Mac IE or Safari, for example, and it's taken me weeks to find out what the problems were.

I have to say I envy you though, I started learning programming with VB, then I moved to web stuff, Javascript and ASP, which I left as soon as I found PHP, but I've always regretted not having a foundation in real programming languages like C or C++, since it's what these higher level languages are all written in.

dnimrodx

12:03 am on Feb 9, 2004 (gmt 0)

10+ Year Member



not having to worry about assigning and releasing memory etc, buffer overruns etc.

That is sooooo true. You can't imagine how better life is with javascript. :)

I have to say I envy you though, I started learning programming with VB, then I moved to web stuff, Javascript and ASP, which I left as soon as I found PHP, but I've always regretted not having a foundation in real programming languages like C or C++, (...)

Isitreal, this is the way I see it: if you can program in PERL, PHP, javascript and coordinate all this with DHTML, clearly you have what it takes (the programming logic) to learn how to program in any language.

If you really regret not having learnt C/C++ or whatever other powerful programming language, you can still have a go at it and learn it -- I am sure you can do it!

Why not try it? ;)

isitreal

3:50 am on Feb 9, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Why not try it? ;)

It's tempting I have to admit, it's a time issue more than anything, too hard to keep up on CSS, which is a relative nightmare to get to run stable, learn PHP well enough, debug javascript issues.

What's a good non MS C/C++ development environment if I ever decide to do that? Is there a good open source one available for windows or do I have to switch to linux (another thing to learn...)

dnimrodx

3:58 pm on Feb 9, 2004 (gmt 0)

10+ Year Member



What's a good non MS C/C++ development environment if I ever decide to do that? Is there a good open source one available for windows or do I have to switch to linux (another thing to learn...)

IMHO, Linux is the best open source platform one can find. In fact I am about to change to Linux as well, not only because of the open_source_scheme, but also because it runs in an UNIX platform -- it has got nothing to do with M$. So, if you are not into developing Windows Applications which you could eventually sell (who knows?), forget about MFC (Microsoft Foundation Classes, available in Visual C++ x.x for Windows API/GUI/etc support) and start as soon as possible learning how Linux OS works, in a first stage, and then learning C. :)

isitreal

6:03 pm on Feb 9, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I've been thinking more and more to start switching to Linux too, there's something nice about the idea that the stuff you learn will actually not become obsolete with the latest MS OS release, or like with asp 3 -> asp.net.

Every maturing open source thing I'm using is really good, firebird, apache, php, they all work great, much better than their MS equivalents as far as I'm concerned. What really gets me is how totally configurable all these are, that's really convenient.

Can't fully switch though since there are too many apps I need in windows that aren't available for the linux platform, plus you have to develop using MS IE as your primary browser test since that's what 90+% of most sites visitors are using.

Thanks for the input, now to find a decently fast box to play with...

dnimrodx

8:27 pm on Feb 9, 2004 (gmt 0)

10+ Year Member



there's something nice about the idea that the stuff you learn will actually not become obsolete with the latest MS OS release, or like with asp 3 -> asp.net.

I feel precisely the same way as you.

Can't fully switch though since there are too many apps I need in windows that aren't available for the linux platform, plus you have to develop using MS IE as your primary browser test since that's what 90+% of most sites visitors are using.

I kind of grew attached and used to Microsoft's OSes as they were the only products available at the time when I first started programming in PCs (and the most sold worldwide.) So it was only until I had reached a mature age when I realised how wrong I have been.

I too can't fully switch to linux platform now, as my professional obligations do not allow me to do so. But, I am not going to abandon the idea just because of that -- whenever I have the time I will get myself a Linux OS and will learn how to use/program it. :)