settimeout

JavaScript: stop execution untill delay is over

社会主义新天地 提交于 2019-12-13 03:45:45
问题 My code is something like this:- function doStuff(){ // Note:- this funcion take 50ms for ececution as i have put // timeout setTimeout(function(){ // some line of code .... }, 50); return; } doStuff(); console.log('This should execute after doStuff() complete its work.") // after that more many lines of code and more stuff are here ..... ..... Now what I want is, as you can see here that doStuff() takes 50ms of time to execute so the code which is after doStuff() it should execute after

Why is this delayed WHILE loop causing a massive memory leak?

北慕城南 提交于 2019-12-13 03:35:15
问题 I ripped a nice trick from somewhere else on this site that allows you to delay the cycles of a loop. I modified it a little for my own use with a Javascript bot that runs on TamperMonkey, in Chrome Version 34.0.1847.131 m. For whatever reason, as soon as the loop is called, a MASSIVE memory leak begins to occur (at about 40,000K - 80,000K per sec) and it doesn't loop at all. My computer already crashed twice because I was neither prepared for nor expecting it. The Function //Tests if Bot is

Is it possible to store setTimeout function inside a localstorage?

怎甘沉沦 提交于 2019-12-13 02:56:05
问题 Provided that I have the javascript code below. var timeout = setTimeout(function(){ alert('this is executed after 5 seconds'); }, 5000); localStorage.setItem('timeout_event', timeout); I have checked the return value of the setTimeout function to be an id or something. If the user refreshes the page, how do I re-run the timeout event? Is it even possible? Any help will do. Thank you in advance. 回答1: I have checked the return value of the setTimeout function to be an id or something. Yes, it

How do I ensure that Javascript's “this” will refer to the object when using setTimeout?

空扰寡人 提交于 2019-12-13 02:48:32
问题 <!doctype html> <html> <head> <title>What is 'this'?</title> <script> function Obj(){ log('Obj instantiated'); } Obj.prototype.foo = function (){ log('foo() says:'); log(this); } Obj.prototype.bar = function (){ log('bar() was triggered'); setTimeout(this.foo,300); } function log(v){console.log(v)} var obj = new Obj(); </script> </head> <body> <button onclick="obj.foo()">Foo</button> <button onclick="obj.bar()">Bar</button> </body> </html> And here is the console output: Obj instantiated foo(

setTimeout is not being called(?)

本小妞迷上赌 提交于 2019-12-13 02:17:47
问题 The issue was my array was [[][][]] instead of [[]] : / This is my Script function loopobject(array) { var me = this; this.array = array; this.loop = function() { counter = 0; while(array.length > counter) { window[array[counter]]('arg1', 'arg2'); counter++; } setTimeout(function(){ me.loop() }, 100); } } var loopinstant = new loopobject(array); window.onload = loopinstant.loop(); The problem arises after the first iteration. I don't know exactly the problem but I'm wondering if its due to

simulating a synchronous XmlHttpRequest

限于喜欢 提交于 2019-12-13 02:08:35
问题 I've read some of the other related questions (Pattern for wrapping an Asynchronous JavaScript function to make it synchronous & Make async event synchronous in JavaScript & there may be more), but I just want to be sure to exhaust all possibilities. Might it be possible to "convert" an asynchronous XmlHttpRequest into a quasi-synchronous one using either setInterval or setTimeout? The idea being that upon success of the Ajax request a variable will be set, which will be the signal for a

How can I set time out for fread when access socket?

和自甴很熟 提交于 2019-12-13 01:28:57
问题 The following is my code. I wish fread can return when there don't have data to read after some seconds. I called stream_set_timeout. But it don't work. And I called stream_get_meta_data too. It don't give my need yet. I am connecting chat.facebook.com. $fp = fsockopen($server, 8888, $errno, $errstr); stream_socket_enable_crypto($fp, true, STREAM_CRYPTO_METHOD_TLS_CLIENT); fwrite($fp, $xml); stream_set_timeout($fp, 5); $str = fread($fp,8192);//This code will hang when there don't have data to

how to set marker one by one in google map api v3?

a 夏天 提交于 2019-12-13 01:24:32
问题 I am doing a google map which will read a set of coordinates and put the marker on the map one by one. Below is my idea: function A{ for loop( set marker call setTimeout('A',2seconds) ) } my idea is to set a marker and use setTimeout to wait 2 seconds and then set the next marker. However, it doesn't work. it show all the markers at the same time and repeat to renew all markers. How can i achieve my goal? Thanks for your help!!!!!!!!!!!!!!! Here is my code: function marker(){ var marker; var

Javascript asynchronous execution queue and setTimeout?

跟風遠走 提交于 2019-12-13 00:37:20
问题 I have a script that I need to bump out of the javascript execution queue. I have found that I can do this with a couple methods. alert();//of course we can't use this one. setTimeout(function(){ someScript();//works, but are there vulnerabilites? }, 1); What other methods are there and what is the correct way to bump out of the javascript execution queue? If setTimeout is the best option, what are the vulnerabilities of using setTimeout? Are there possible future problems, possibility that

Delay mousedown interval start (JQuery / Javascript)

半城伤御伤魂 提交于 2019-12-13 00:08:55
问题 I am writing a jQuery plugin that manipulates the value of an input field at the press of a button. What I have so far is the ability to control the value by clicking the button, as well as to continually increase it if the user holds the button pressed. Simplified, the script is something like this: var element = $('#test-input'); var interval; $('#test-up-button').on({ mousedown : function(e) { element.val(parseInt(element.val()) + 1); //Wait 400ms, than do the interval interval = window