- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
I've seen developers struggle with that issue many times. Emphasis on "developers struggle."
Admin
Admin
the lblWaitClock isn't the issue, it's the ctl00_ before it. That's there because there's a server parsed control wrapping the label, that hasn't been named by the developer. If you understand why the "decoration" is there, you have plenty of control over it...
Admin
There's that thing called Synestesia that can help you with that.
Admin
Unless Current_Time = local user's time (taken with JS function) and not server time.
ingenium - material my brain is made of.
Admin
Admin
Admin
I guess this week's WTF is the comments section ...
"I've never touched Javascript in my life and think that AJAX is a language ... but I'll open my dumb mouth and spout my useless opinion anyway! Here's some entirely irrelevant C psuedo-code!"
CAPTCHA: augue - I can't believe the augue of these people.
Admin
Javascript is single threaded and doesn't have the concept of sleep. It's a big neverending event listener waiting for the browser to give it events to process. What's done in the code showed in the article is putting a handler in the browser's js engine queue at the given time. So actually, it is a sleep-less solution. At least part of your requirements is met. The part about accuracy isn't doable. Precisely because js is single-threaded: you have the garantee that the handler will be in the queue at the time you specified, but if one or several previous handlers take more than a second to execute, your time handler execution will be delayed.
By talking about the sleep command, the article mislead the readers with a wrong analogy.
That's said, all the commenters saying to others that they don't know js but who haven't been able to spot that can go back to basic js learning.
Admin
User's time: X is assigned. User's clock jumps ahead 1 hour. Current time is 1 hour later than X. User gets logged out.
Server time: X is assigned. Server's clock jumps ahead 1 hour. Current time is 1 hour later than X. User gets logged out.
Admin
Admin
Ok, I can be more precise if you want, javascript is single-threaded, except if you create a web worker dedicated to a task (fully detached from the window context), which will miserably fail on IE < 10 and android browsers, with no possibility to emulate the behavior. can i use web workers? And that changes nothing about my previous point: the way showed in the article is single threaded and without sleep. (and I don't think web workers support sleep either).
Admin
The accuracy is totally doable - there was a clue in the article.
Do not expect 'setTimeout' to give you accurate times, so rather than 'setTimeout(updateTimer, 1000)', use 'setTimeout(updateTimer, 100)' and use 'new Date().getTime()' to get the time in ms since your timeout period started.
Then it doesn't matter how much time is actually between the setTimeout events, you can still show the time to within 100ms or so (if you need more accuracy, increase the frequency of the setTimeouts
Admin
Admin
Yes, it is doable. The fact that it uses an event loop instead of threading is unrelated to this. Even in a threaded solution you would need to use the same approach to preserve accuracy.
It's true that javascript doesn't have the true concept of "sleep", but again this has nothing to do with threads. A true sleep function involves cooperation with the hardware, namely the halt instruction (HLT).
Admin
I second this, TRWTF is not knowing what "smart programmers" really do. Use calls that do a callback, interrupt, or some equivalent when time is up. Don't poll!
Admin
What exactly did the article say that "smart programmers" do that was not correct?
It said they "check the actual time after being awakened so as not to allow the difference between requested and actual sleep time to skew things."
That is exactly how you should implement a timer display refresh. It has nothing to do with polling.
Admin
I'm sorry, I've read too quickly and missed the part mentionning the absence of sleep. Of course, checking the actual date before updating your 'clock' is mandatory. And I agree about the fact that using setTimout/setInterval can give you a good level of precision, but this assumes that your 'clock' is the only thing running, or at least no time-consuming task have been put in the queue. (and no long garbage collection occurs) Checking the time will enable you to correct your 'clock' with the right amount of time passed, but you won't be able to garantee that your 'display' will show every passing second, that's what I meant by saying that no real accuracy can be achieved. Again, mpy bad, should have been more precise instead of assuming a context without explaining it. Always documenting your assumption ^^'
Admin
For the part about accuracy, see my previous post. I was initially answering to a post in first page stating:
So I both:
For the part about thread and sleep, what I meant is, a language like javascript, being mainly used single-threaded, won't implement it, because the sleep would block everything, and you usually don't want to do that (or to allow that if you're a browser vendor). That is for me the relation between the 'single threaded' and 'no sleep'. It wasn't about a real technical impossibility.
Sorry again, I'm not a native English speaker, and what's crystal clear in my head appears to be not so clear when written down.
Admin
Admin
НОВИНКИ КИНО И СЕРИАЛЫ https://kinohd.rip/
https://kinohd.rip/inte - Зарубежные https://kinohd.rip/russ - Отечественные https://kinohd.rip/top-filmov-i-serialov.html - ТОП Кино https://kinohd.rip/top-serialov.html">ТОП Сериалов https://kinohd.rip/top-filmov.html - ТОП Фильмов
Admin
НОВИНКИ КИНО И СЕРИАЛЫ https://kinohd.rip/
https://kinohd.rip/inte - Зарубежные https://kinohd.rip/russ - Отечественные https://kinohd.rip/top-filmov-i-serialov.html - ТОП Кино https://kinohd.rip/top-serialov.html">ТОП Сериалов https://kinohd.rip/top-filmov.html - ТОП Фильмов
Admin
Джойказино https://joycasino-2c9.ru/