Hardmath123 wrote:
blob8108 wrote:
Hardmath123 wrote:
Well, ideally I would start a new thread from the clock function, which (AFAIK) would not cause the recursion error. I think that's nicer, because functions that go into infinite loops never really appealed to me, probably because of my JS background where you'll freeze the browser.I don't understand that Why does the clock function want to call itself at all? Surely a while loop is what you want...
I didn't get this either in the beginning, but here's the deal: in JS, the browser tries to run all code until it's over, and if it takes long you get the spinning colorful wheel (of death). Try running this:
Code:
while (true) { }It freezes.
So what you want to do in JS is to set up a timer which starts a new thread after a slight delay:Code:
function loop() { // ... window.setTimeout(loop,1); }This way you keep going up and running the loop every millisecond. Get it?
EDIT: Of course, the modern newfangled way to do it is to use RequestAnimationFrame() which basically asks the browser politely to animate it while the browser gets to be stingy with resources (including pausing/slowing down animations when the tab is blurred).
It's in Python not JavaScript.
Offline
Hardmath123 wrote:
blob8108 wrote:
Hardmath123 wrote:
Well, ideally I would start a new thread from the clock function, which (AFAIK) would not cause the recursion error. I think that's nicer, because functions that go into infinite loops never really appealed to me, probably because of my JS background where you'll freeze the browser.
I don't understand that Why does the clock function want to call itself at all? Surely a while loop is what you want...
I didn't get this either in the beginning, but here's the deal: in JS, the browser tries to run all code until it's over, and if it takes long you get the spinning colorful wheel (of death). Try running this:
Code:
while (true) { }It freezes.
So what you want to do in JS is to set up a timer which starts a new thread after a slight delay:Code:
function loop() { // ... window.setTimeout(loop,1); }This way you keep going up and running the loop every millisecond. Get it?
EDIT: Of course, the modern newfangled way to do it is to use RequestAnimationFrame() which basically asks the browser politely to animate it while the browser gets to be stingy with resources (including pausing/slowing down animations when the tab is blurred).
Yeah, dong what you describe makes sense in Javascript. But as nXIII points out, JS doesn't even have proper threading
And for a simple Python script that runs in a terminal, I don't think we need to worry about blocking the UI...
Last edited by blob8108 (2012-11-18 12:27:22)
Offline
roijac wrote:
Hardmath123 wrote:
So what you want to do in JS is to set up a timer which starts a new thread after a slight delay:
Code:
function loop() { // ... window.setTimeout(loop,1); }This isn't recursive
It's a form of tail-call recursion. (The tail call is just delayed.)
Last edited by nXIII (2012-11-18 14:41:56)
Offline
nXIII wrote:
roijac wrote:
Hardmath123 wrote:
So what you want to do in JS is to set up a timer which starts a new thread after a slight delay:
Code:
function loop() { // ... window.setTimeout(loop,1); }This isn't recursive
It's a form of tail-call recursion. (The tail call is just delayed.)
Yeah, it's like
when I receive [loop v] do something broadcast [loop v]
Offline
Hardmath123 wrote:
nXIII wrote:
roijac wrote:
This isn't recursive
It's a form of tail-call recursion. (The tail call is just delayed.)
Yeah, it's like
when I receive [loop v] do something broadcast [loop v]
i dont think so because AFAIK window.setTimeout will just push a function to the event queue and close the stack for this call of the function [ as it reaches the end] so its not like
when I receive [loop v] do something broadcast [loop v]But its more like
Last edited by fanofcena (2012-11-18 22:24:12)
Offline
fanofcena wrote:
i dont think so because AFAIK window.setTimeout will just push a function to the call stack and close the stack for this call of the function [ as it reaches the end]
…
There is a call stack that javascript engines [ spidermonkey or v8 etc] mantain for calling functions [thats why they are so beautifully asynchronous]
Not really. JavaScript engines have a task queue of tasks which are executed serially. When you call setTimeout, it schedules a new task to execute at some time at or after the given interval. Thus the following function: (4 being the specified minimum)
function f() { setTimeout(f, 4); }
…just schedules itself to execute 4 ms later.
so if u call the following 3 callbacks from native code
foo();
foo2();
foo3();
it will just push 3 functions in call stack and execute them accordingly. when the execution for the current event loop has happened.
Normal function calls in ECMAScript are synchronous, not asynchronous. The current event loop is maintained while the function is executed. It doesn't push any of those functions onto the stack; it invokes foo with zero arguments and ignores the result, invokes foo2 with no arguments and ignores the result, and lastly invokes foo3 with no arguments and ignores the result. If that's in a function, it finishes executing the rest of the function, pops the stack frame, and continues from there until it's finished the current task. Then it moves on to the next task in the event loop (e.g. a timeout or an event firing).
you can just do
Loop(){
setTimeout(Loop,1);
}
That's not even syntactically valid JavaScript…
EDIT: You edited your post a bit…
EDIT2:
And setTimeout is just a hack with the equeue ;-) nothing big
It's not a hack, it's a language feature.
Last edited by nXIII (2012-11-18 22:43:39)
Offline
nXIII wrote:
fanofcena wrote:
i dont think so because AFAIK window.setTimeout will just push a function to the call stack and close the stack for this call of the function [ as it reaches the end]
…
There is a call stack that javascript engines [ spidermonkey or v8 etc] mantain for calling functions [thats why they are so beautifully asynchronous]Not really. JavaScript engines have a task queue of tasks which are executed serially. When you call setTimeout, it schedules a new task to execute at some time at or after the given interval. Thus the following function: (4 being the specified minimum)
Code:
function f() { setTimeout(f, 4); }…just schedules itself to execute 4 ms later.
so if u call the following 3 callbacks from native code
foo();
foo2();
foo3();
it will just push 3 functions in call stack and execute them accordingly. when the execution for the current event loop has happened.Normal function calls in ECMAScript are synchronous, not asynchronous. The current event loop is maintained while the function is executed. It doesn't push any of those functions onto the stack; it invokes foo with zero arguments and ignores the result, invokes foo2 with no arguments and ignores the result, and lastly invokes foo3 with no arguments and ignores the result. If that's in a function, it finishes executing the rest of the function, pops the stack frame, and continues from there until it's finished the current task. Then it moves on to the next task in the event loop (e.g. a timeout or an event firing).
you can just do
Loop(){
setTimeout(Loop,1);
}That's not even syntactically valid JavaScript…
EDIT: You edited your post a bit…
EDIT2:And setTimeout is just a hack with the equeue ;-) nothing big
It's not a hack, it's a language feature.
Lol its not a language feature , its a browser feature
setTimeout is not part of ECMA-262,
http://stackoverflow.com/questions/12335222/settimeout-and-v8
don't confuse browser with the language. javascript core is different browsers provide javascript + bunch_of_w3 specs
Last edited by fanofcena (2012-11-18 22:53:44)
Offline
and i mentioned calling them from native code for example you are writing a binding for node.js or via NaCl in C++ that is native code
so it u are calling those 3 functions from native code it will just push them into the event stack and execute them accordingly..
code example ?
#include<v8.h> #include<node/node.h> #include<node/uv.h> using namspace node; using namspace v8; /* Some code omitted here */ Persistent<Function> foo; void some_Long_Task(uv_req){ sleep(400); // sleeps for 400 second } void callback(uv_req){ Handle<Value> _Args[3] = { Integer::New(8),String::New("Fooo"),Object::New(); }; foo->Call(Context::GetCurrent()->Global(),3,_Argv); } Handle<Value> Foo(Arguments &args){ HandleScope handle; foo = Persistent<Function>::New( Function::New(args[0])); uv_work_t * req = new uv_work_t; uv_queue_work(uv_default_loop(),req,Long_Task,callback); handle.Close(Undefined()); } void Init(Handle<Object> target) { Local<FunctionTemplate> Tester = FunctionTemplate::New(Foo); } NODE_MODULE(foonative, Init)
Now the javascript code to use this
foo = require('./foonative.node'); var foo1 = new foo(function(a,b,c){ console.log(a,b,c); }); var start = Date.now(); while(Date.now() - start > 30000 ){ /* I am going to make javascript confused */ }; // the output of the above code will come after 30 seconds cause the awesome while loop wont let it rest ;-)
@Nxii now u get my point ? the native code will just push it back into the equeue of the event stack.
Last edited by fanofcena (2012-11-18 23:12:06)
Offline
fanofcena wrote:
Lol its not a language feature , its a browser feature
setTimeout is not part of ECMA-262,
http://stackoverflow.com/questions/12335222/settimeout-and-v8
don't confuse browser with the language. javascript core is different browsers provide javascript + bunch_of_w3 specs
I know. I linked to the whatwg html standard that defines it.
I wrote:
Thus the following function: (4 being the specified minimum)
I was simplifying it for the sake of other people
so it [sic] u [sic] are calling those 3 functions from native code it will just push them into [sic] the event stack and execute them accordingly..
I'm sorry, but when I see the following example:
foo(); foo2(); foo3();
I do not assume those are three native functions.
EDIT: This is getting seriously off-topic…
Last edited by nXIII (2012-11-18 23:31:01)
Offline
nXIII wrote:
fanofcena wrote:
Lol its not a language feature , its a browser feature
setTimeout is not part of ECMA-262,
http://stackoverflow.com/questions/12335222/settimeout-and-v8
don't confuse browser with the language. javascript core is different browsers provide javascript + bunch_of_w3 specsI know. I linked to the whatwg html standard that defines it.
I wrote:
Thus the following function: (4 being the specified minimum)
I was simplifying it for the sake of other people
so it [sic] u [sic] are calling those 3 functions from native code it will just push them into [sic] the event stack and execute them accordingly..
I'm sorry, but when I see the following example:
Code:
foo(); foo2(); foo3();I do not assume those are three native functions.
EDIT: This is getting seriously off-topic…
It was already a recursively off-topic post ,
okay i explicitely mentioned that assume these 3 functions are called from native code x_x duh
[qoute=fanofcena]
so if u call the following 3 callbacks from native code
[/qoute]
PS ;D everything not ECMA-262 can be called as a browser only hack ;D ;D
return Topic; // with this we shall go back to topic
Offline
fanofcena wrote:
okay i explicitely mentioned that assume these 3 functions are called from native code x_x duh
fanofcena wrote:
so if u call the following 3 callbacks from native code
Sorry, I assumed you had omitted something.
Last edited by nXIII (2012-11-18 23:43:18)
Offline
nXIII wrote:
fanofcena wrote:
okay i explicitely mentioned that assume these 3 functions are called from native code x_x duh
fanofcena wrote:
so if u call the following 3 callbacks from native code
Sorry, I assumed you had omitted something.
It happens :-) , my wording has made even me confused if i said it or not ;-D so u know i speak confusingly ...
Offline
Upload it to media fire, or sourceforge. I ran across this problem when uploading my python and java projects.
Offline
TheSupremeOverLord wrote:
Upload it to media fire, or sourceforge. I ran across this problem when uploading my python and java projects.
Your sig says that the image in it is no longer available. Is that deliberate?
Offline
JH1010 wrote:
TheSupremeOverLord wrote:
Upload it to media fire, or sourceforge. I ran across this problem when uploading my python and java projects.
Your sig says that the image in it is no longer available. Is that deliberate?
No, I deleted my sig by accident
Offline
To upload application files, run the appcfg.py command with the update action and the name of your application's root directory. The root directory should contain the app.yaml file for the application.
appcfg.py update myapp/
appcfg.py gets the application ID from the app.yaml file, and prompts you for the email address and password of your Google account. After successfully signing in with your account, appcfg.py stores a "cookie" so that it does not need to prompt for a password on subsequent attempts.
You can specify the email address on the command line using the --email option. You cannot specify the password as a command line option.
appcfg.py --email=Albert.Johnson@example.com update myapp/
Only application owners and the developer who uploaded the code can download it. If anyone else attempts to download the app, they'll see an error message like the following:
Fetching file list...
Email: user@example.com
Password for user@example.com:
Error 403: --- begin server output ---
You do not have permission to download this app version.
--- end server output ---
Offline