javascript - How to use setTimeout and get a return variable? -
I have a function geocode that works ... I want to implement a delay to prevent query boundary errors I am trying, and here is my javascript:
tmpResult = null; Set timeout (tmpResult = geocode (features [j], cities [j], state [j]),} 100);
variable tmpResult
is the result of my geocode .. However, tmpResult
is null
when I run the script .. am I missing?
Thanks! What do you have to do to If you try to do this, you have found: Because your FYI, you should make sure that setTimeout ()
tmpResult
is completely valid when < Code> setTimeout () runs and then you may find this issue possible that you are trying to use setTimeout ()
before tmpResult
. Remember, this will run 100MMS in the future. Your other JavaScript will continue to run before that time. tmpResult
use the value setTimeout ()
or call some function and pass it in the value of tmpResult
. setTimeout ()
is asynchronous and you can not synchronize while using it. You should have asynchronous code which means the value of means tmpResult
until the timer executes the callback so that you can not try to use it before the timer callback is activated is not valid.
var tmpResult = null; Set timeout (function (tmpResult = geocode (features [j], cities [j], state [j]);}, 100); console.log (tmpResult);
console.log (tmpResult)
will be played before the statement timer becomes active, it will not work tmpResult
is not yet a value.
geocode ()
not even an asynchronous function because if it is, then you will have to code asynchronously with There are too.
Comments
Post a Comment