/    Sign up×
Community /Pin to ProfileBookmark

Can I have more than 1 timer?

I need to run two cycles – at different speeds. Is there a way to set up 2 or more timers in javascript?

to post a comment
JavaScript

6 Comments(s)

Copy linkTweet thisAlerts:
@rickqinJan 01.2006 — it seems about thread.
Copy linkTweet thisAlerts:
@42OldsauthorJan 01.2006 — it seems about thread.[/QUOTE]
O.

K.

Care to elaborate?
Copy linkTweet thisAlerts:
@rickqinJan 01.2006 — i don't know why you need to set two timer? i think one timer is just like a timeseed. you can do some calculation with the standard timer's value, and then, you will get two different time.

i'm from china, i can't express my thought exactly, if you can understand me?
Copy linkTweet thisAlerts:
@42OldsauthorJan 01.2006 — i don't know why you need to set two timer? i think one timer is just like a timeseed. you can do some calculation with the standard timer's value, and then, you will get two different time.

i'm from china, i can't express my thought exactly, if you can understand me?[/QUOTE]

Yes, well enough.

I think I understand what you mean, and I could go that way - but I'm looking for alternitives first. I need to run 2 independent processes, each not aware of the other, and would like to keep it as simple as possible.

Thanks.
Copy linkTweet thisAlerts:
@SpectreReturnsJan 01.2006 — <i>
</i>function thread1() {
alert("This is run every second.");
}

function thread2() {
alert("This is run every two and a half seconds.");
}

t1 = setInterval(1000, "thread1();"); // run one thread every second
t2 = setInterval(2500, "thread2();"); // run other thread every 2.5 seconds

setTimeout(12000, "clearInterval(t1); clearInterval(t2);"); // after 12 seconds stop both from executing
Copy linkTweet thisAlerts:
@42OldsauthorJan 01.2006 — <i>
</i>function thread1() {
alert("This is run every second.");
}

function thread2() {
alert("This is run every two and a half seconds.");
}

t1 = setInterval(1000, "thread1();"); // run one thread every second
t2 = setInterval(2500, "thread2();"); // run other thread every 2.5 seconds

setTimeout(12000, "clearInterval(t1); clearInterval(t2);"); // after 12 seconds stop both from executing
[/QUOTE]

OK, thanks - that'll work.

I also found some more info at http://www.devshed.com/c/a/JavaScript/Using-Timers-in-JavaScript/2/

Thanks for the help the program is running circles around itself, just as it should. Great way to start off the new year!
×

Success!

Help @42Olds spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...