“You’ve gotta poop on yourself before you crawl.” — Jason
My 12 classmates and I spent 10+ hours a day programming. So far, we’ve worked on…
- Teaching robots how to dance on the page
- DOM manipulation exercises
- Understanding event listeners
…and things are finally starting to click. And by click, I mean that the frustrating attempt to figure out how to solve countless puzzles are starting to seem almost…enjoyable. One of my biggest challenges was coming to terms with the fact that making messy mistakes and screwing everything up before piecing everything back together is simply part of the creative process. Frustrating, terrifying, but ultimately gratifying process. “Gotta poop on yourself before you crawl,” said my classmate Jason, while working through his millionth attempt to make a button work just so. )He figured it out after a while, of course, being far more patient than I could ever hope to be…)
That is Phase I. Phase II is infinitely more complicated. The clock has to update itself on the page by the millisecond, synced up to the colors, which also change. That is where asynchronous JS and event loops come in.
As the introduction to these concepts, I watched Phil Roberts’s 2014 conference keynote presentation What the Heck is the Event Loop, Anyway?
The short answer to the posed question is: I’m still not sure. I heard words. Some words I recognized. Some new words were introduced. It’s all pretty intimidating. But not hopeless! I’ve learned these things:
- The call stack records where in the program we are.
- Blocking — things that are slow, stuck in processing. You shouldn’t create too many functions that block the stack if you want to have nice fluid UIs.
- Solution to blocking: asynchronous callbacks — run some code, give it a callback (for example, set a timer), run that later.
- Event loop has one simple job. It looks at the stack and at the task queue. If the stack is empty, it takes the first thing on the queue and pushes it onto the stack, which effectively runs it.
That’s all I got. I’m hoping the lecture will provide more clarification. Check back to look at the updated clock, which will hopefully be as beautiful and functioning as it should be pretty soon!