How to wait until canvas has finished re-rendering?

Steven Choi

I have a renderText() function that fills out the canvas with text (ctx.fillText(char, charLocation, 400)). I want it to render the text, pause for 2 seconds, and render new text.

Workaround:

renderText();
setTimeout(() => {
    renderNewText();
}, 2000);

This solution is fine for now, but what if I want to decrease it to 0.1 seconds, and renderText() takes more than 0.1 seconds to execute, resulting in renderNewText() executing before renderText()? How can I, for sure, wait until renderText() is finished with fillText before pausing however long I want to pause?

What I know: I'm aware that canvas and context render entirely synchronously; as such, renderText() doesn't return any promises and all the methods called on the context continue even after exiting renderText(). Also, there are no events that can signal when it's done, at least according to all the comments and threads I've read. In all the solutions I've looked up on Stack Overflow, the answer is pretty much "You can't", but I find that hard to believe.

I'm sure there must be something I'm really not getting here, probably the event loop or Promises or something else.

Steven Choi

From @towc's comment

canvas api calls are asynchronous, sure, but they're queued, so the order is preserved. To know more about this, read up on the event loop. If you have a race condition, it's somewhere else

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to wait until networking by Alamofire has finished?

From Dev

Android - How to wait until a SnapshotListener has finished?

From Dev

Wait until gobalEval has finished

From Dev

Wait until gobalEval has finished

From Dev

How to make a python Script wait until download has finished

From Java

How to wait until all async calls are finished

From Dev

How to wait until an animation is finished in Swift?

From Dev

How to wait until all NSOperations is finished?

From Dev

how to wait until a web request with HttpWebRequest is finished?

From Dev

How to wait until some jQuery methods are finished?

From Dev

How to wait until my batch file is finished

From Dev

How to get jQuery to wait until an animation is finished?

From Dev

How do I wait to delete a file until after the program I started has finished using it?

From Dev

How to wait until find method has finished before doing further processing in Ember Model

From Dev

How can I force this jquery to wait until click event has finished?

From Dev

Wait until function is finished

From Dev

Why the main does not wait until the async method has finished?

From Dev

Swift wait until dataTaskWithRequest has finished to call the return

From Dev

Can a for-loop wait until a function within it has finished executing?

From Dev

Download files from UIDocumentPicker and wait until download has finished

From Dev

Launch an application and wait until it has finished without blocking redraw

From Dev

How to know when the DOM has finished rendering

From Dev

How to wait until all tasks are finished before running code

From Dev

How to wait until all tasks finished without blocking UI thread?

From Dev

How to make python wait until the previous task is finished?

From Dev

In NodeJs how can I wait until my http get is finished?

From Dev

How to make Gulp wait until dest file is finished?

From Dev

How do I make an Excel RefreshAll wait to close until finished?

From Dev

How to make python wait until the previous task is finished?

Related Related

  1. 1

    How to wait until networking by Alamofire has finished?

  2. 2

    Android - How to wait until a SnapshotListener has finished?

  3. 3

    Wait until gobalEval has finished

  4. 4

    Wait until gobalEval has finished

  5. 5

    How to make a python Script wait until download has finished

  6. 6

    How to wait until all async calls are finished

  7. 7

    How to wait until an animation is finished in Swift?

  8. 8

    How to wait until all NSOperations is finished?

  9. 9

    how to wait until a web request with HttpWebRequest is finished?

  10. 10

    How to wait until some jQuery methods are finished?

  11. 11

    How to wait until my batch file is finished

  12. 12

    How to get jQuery to wait until an animation is finished?

  13. 13

    How do I wait to delete a file until after the program I started has finished using it?

  14. 14

    How to wait until find method has finished before doing further processing in Ember Model

  15. 15

    How can I force this jquery to wait until click event has finished?

  16. 16

    Wait until function is finished

  17. 17

    Why the main does not wait until the async method has finished?

  18. 18

    Swift wait until dataTaskWithRequest has finished to call the return

  19. 19

    Can a for-loop wait until a function within it has finished executing?

  20. 20

    Download files from UIDocumentPicker and wait until download has finished

  21. 21

    Launch an application and wait until it has finished without blocking redraw

  22. 22

    How to know when the DOM has finished rendering

  23. 23

    How to wait until all tasks are finished before running code

  24. 24

    How to wait until all tasks finished without blocking UI thread?

  25. 25

    How to make python wait until the previous task is finished?

  26. 26

    In NodeJs how can I wait until my http get is finished?

  27. 27

    How to make Gulp wait until dest file is finished?

  28. 28

    How do I make an Excel RefreshAll wait to close until finished?

  29. 29

    How to make python wait until the previous task is finished?

HotTag

Archive