Skip to content
Advertisement

Tag: settimeout

How to make a promise from setTimeout

This is not a realworld problem, I’m just trying to understand how promises are created. I need to understand how to make a promise for a function that returns nothing, like setTimeout. Suppose I have: How do I create a promise that async can return after the setTimeout is ready to callback()? I supposed wrapping it would take me somewhere:

javascript canvas doesn’t draw images

I’m developing hybrid javascript app for android using cordova. In the following code I use two ways of drawing image on canvas: with setTimeout and without. Following code (wrapped with cordova) on android device doesn’t react on func1 but does react on func2. The second click on func1 finally draws image on a canvas. Which is completely strange. I assume

Hold button -> repeat function

I’m trying to achieve something which souldn’t be hard to do, but everything I’ve tried so far hasn’t worked. I have a function that changes a value every time I click a button, and what I want is: when I hold this button, the value should keep changing. This is what I’ve tried and hasn’t worked, setInterval and setTimeout won’t

Wait until setInterval() is done

I would like to add a small dice-rolling effect to my Javascript code. I think a good way is to use the setInterval() method. My idea was the following code (just for testing): Now I would like to wait for the setInterval until it is done. So I added a setTimeout. This code works quite okay. But in my main

Is it possible to chain setTimeout functions in JavaScript?

Is it possible to chain setTimout functions to ensure they run after one another? Answer Three separate approaches listed here: Manually nest setTimeout() callbacks. Use a chainable timer object. Wrap setTimeout() in a promise and chain promises. Manually Nest setTimeout callbacks Of course. When the first one fires, just set the next one. Chainable Timer Object You can also make

Can setTimeout ever return 0 as the id?

I am writing a check to see if a timeout is active. I was thinking of doing this: I was wondering if it would ever be possible that a will be 0. In that case I would use a !== null Answer First: 0 isn’t the same as null, (0 == null) would be false in every case’; if you

Advertisement