I don’t know about your brains, but mine has a habit of trying to link random things together. This is especially true when I am learning something new and trying to wrap my brain around new concepts. I have been taking a programming course at NTV Promennt and a few days ago I found myself sitting on my couch, crocheting a floor turtle (a familiar term by now to many of the crafting persuasion I should think, for those not in the know: stay with me) and wondering which programming concept out of the ones I have been wrestling with of late could be explained with the help of said floor turtle.
Another fun thing about my brain is I learn best when trying to explain things to other people. So now I am going to explain how my 100% cotton, crochet floor turtle mop is like a finally{} block, and in that context, how asking my kids to clear the dinner table and load the dishwasher is an async function.
I am not an expert on async functions or programming in general, but I’m pretty familiar with having kids and if you are not, let me tell you: if it is not their idea, they will not be doing anything you ask instantly. So here’s how it goes in geek speak:
const askKidsToLoadDishwasher = async () => { setDishwasherLoading(true); try { await clearDinnerTable(); //patience required, it will happen...maybe await loadDishwasher(); //another promise, another wait console.log("dishwasher loaded! Great job kids! now leave mommy alone, please"); } catch (arguments) { console.error("something went wrong", arguments.message); //we expect things to end here really //this is where the "I don't wannaaa" "why cant they do it!" //and possibly broken plates go. } finally { mopUpSpillsFromFloor(); //here is where my floor turtle lives //here it will happily mop up spills off the floor, regardless of the success of the big ask, because there will always be spills setDishwasherLoading(false); //at this point, at least the kids aren't doing it, but we might have to call getDadOnTheJob() once this is over... }};
It’s short, it’s silly, but this is where my floor turtle will permanently live in my brain now…and on my floor. Also, it is worth noting that with two kids, such as myself, you could have the two awaits running side by side with an await Promise.all([clearDinnerTable(), loadDishWasher()]) , because one kid can do the clearing of the table while the other does the loading of the dishwasher, so you don’t have to wait for one to finish entirely before the other can start.
And finally {pun intended}, a note on the floor turtle: it is esentially a mop that lives on your floor, but because it is cute no one will think you lazy or messy for leaving it on the floor…but as you actually ARE lazy AND have a serious dislike for wet socks, you can mop up small spills with minimum effort, just by stepping on the poor cute little animal and rubbing it’s belly all over your messy floor.


Leave a comment