Book Section
-----
TY JavaScript 3rd Ed.
Teach Yourself JS 1.5
Teach Yourself DHTML
Teach Yourself JS 1.3
LLWW: JavaScript

General Section
-----
Discussion Forum
Articles / Tips
JavaScript Links
About the Author
Privacy Policy
Contact Me



Other Sites
-----
Website Workshop
JavaScript Weblog

JavaScript Workshop Forums

 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
yield execution in javascipt

 
Post new topic   Reply to topic    JSWorkshop Forum Index -> JavaScript
View previous topic :: View next topic  
Author Message
kewpie_007
New member
New member


Joined: 25 Jun 2012
Posts: 1
Location: China

PostPosted: Mon Jun 25, 2012 2:26 am    Post subject: yield execution in javascipt Reply with quote

This post is to discuss whether the capability of yielding execution in javascript is helpful and welcomed.

I hit an async-to-sync issue when to implement some synchronous API using asynchronous API. After asynchronous API is called, I want to wait for result for a while and return then. However, the result is set in callback way, and it's impossible to wait by busy while loop, because otherwise callback would never be called.

If javascript could conditionally yield its execution to browser, and then browser would be able to schedule other workable tasks and invoke callbacks. Once condition is met, execution can resume from yield point again.

In this way, nothing will be blocked, whereas, we can achieve some synchronous program style.

I have tried this out in Chromium (w/ necessary change), and it works pretty well.

Wondering if you have any comment.
Back to top
View user's profile Send private message
phil karras
Senior Member
Senior Member


Joined: 15 Jul 2002
Posts: 1776
Location: MD

PostPosted: Tue Jun 26, 2012 5:48 am    Post subject: Reply with quote

Try using either the "setTimeout, clearTimeout" methods or the set & clearInterval() methods.

here's a good explination of how & when to use these methods:

http://www.w3schools.com/js/js_timing.asp
_________________
Phil K
Circle Software Consulting
Test website: http://cs.yrex.com/
Guidelines for Posting: http://www.jsworkshop.com/posting.html
IHBAAA = It Has Been Asked And Answered
KISS: http://www.jsworkshop.com/bb/viewtopic.php?t=508
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    JSWorkshop Forum Index -> JavaScript All times are GMT - 7 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2002 phpBB Group
(c) 1997-2002 Starling Technologies and Michael Moncur. Portions (c) Sams Publishing.