JSJ 399:  Debugging with Async/Await with Valeri Karpov

EPISODE · Oct 10, 2019 · 1H 3M

JSJ 399: Debugging with Async/Await with Valeri Karpov

from JavaScript Jabber · host Charles M Wood

Valeri Karpov is a maintainer on Mongoose, has started a few companies, and works for a company called Booster Fuels. Today’s topic debugging with Async/Await. The panel talks about some of the challenges of debugging with Async. AJ, however, has never encountered the same problems, so he shares his debugging method. Valeri differentiates between .catch vs try...catch, and talks about why he prefers .catch. There are two ways to handle all errors in an async function without leading to an unhandled promise rejection. The first is to wrap the entire body of the async function in a try...catch, has some limitations. Calling an async function always returns a promise, so the other approach is calling .catch on the promise to handle any errors that occur in that function body. One of the key differences is if you return a promise within an async function, and that return promise is wrapped in a try...catch, the catch block won’t get called if that promise is rejected, whereas if you call .catch on the promise that the function returns, you’ll actually catch that error. There are rare instances where this can get tricky and unintuitive, such as where you have to call new promise and have resolve and reject, and you can get unexpected behavior.The panel discusses Valeri’s current favorite JS interview question, which is,  “Given a stream, implement a function called ‘stream to promise’ that, given a stream, returns a promise that resolves to the concatenation of all the data chunks emitted by the stream, or rejects if the stream emits an error event.” It’s really simple to get this qustion right, and really simple to get it wrong, and the difference can be catastrophic. AJ cautions listeners to never use the data event except in the cases Val was talking about, only use the readable event.The conversation turns to the function of a readable event. Since data always pushes data, when you get a readable event, it’s up to you to call read inside the function handler, and then you get back a chunk of data, call read again and again until the read returns null. When you use readable, you are in control and you avoid piling functions into RAM. In addition, the right function will return true or false to let you know if the buffer is full or not. This is a way to mix imperative style into a stream.The next discussion topics are the differences between imperative style and reactive style and how a waits and promises work in a normal four loop. A wait suspends the execution of a function until the promise is resolved. Does a wait actually stop the loop or is it just transpiling like a promise and it doesn’t stop the loop. AJ wrote a module called Batch Async to be not as greedy as promise.all but not as limited as other options.The JavaScript panelists talk about different async iterators they’ve used, such as Babel. They discuss the merits of Babel, especially since baseline Android phones (which a significant portion of the population of the world uses) run UC Browser that doesn’t support Babel, and so a significant chunk of the population of the world. On the other hand, if you want to target a large audience, you need to use Babel.Since frameworks in general don’t handle async very well, the panel discusses ways to mitigate this. They talk about different frameworks like Vue, React, and Express and how they support async functions. They discuss why there is no way for you to actually cancel an async option in an actual case, how complex canceling is, and what you are really trying to solve for in the cancellation process. Canceling something is a complex problem. Valeri talks about his one case where he had a specific bug that required non-generic engineering to solve, and cancelling actually solved something. When AJ has come across cancellation issues, it’s very specific to that use case. The rest of the panelists talk about their experiences with having to cancel something. Finally, they talk about their experience with async generator functions. A generator is a function that lets you enter into the function later. This makes sense for very large or long running data sets, but when you have a bounded items, don’t complicate your code this way. When an async generator function yields, you explicitly need to call next in order for it to pick up again. If you don’t call ‘next’, it’s essentially cancelled. Remember that object.keys and object.values are your friends. PanelistsChristopher BuechelerAJ O’NealCharles Max WoodWith special guest: Valeri KarpovSponsorsThe DevEd PodcastSentry use the code “devchat” for 2 months free on Sentry’s small plan Adventures in DevOpsLinksMongooseExpress 5Node StreamsPull StreamsMasteringjs.ioMongoDBBabelHTMLWebpackVueExpressRxJSConsole.logJson.stringifyBatchasync.jsHow to Write Batch Async Functions Follow DevChatTV on Facebook and Twitter PicksAJ O’Neal:Ethan Garofolo YouTubeChristopher Buecheler:Functional Design Patterns for Express.jsCharles Max Wood:Microsoft IgniteMaxcoders.ioValeri Karpov: Follow Valeri on Twitter @code_barbarian and Github @vkarpov15Masteringjs.ioJurassic Park: A NovelSpecial Guest: Valeri Karpov. Support this podcast at — https://redcircle.com/javascript-jabber/donationsPrivacy & Opt-Out: https://redcircle.com/privacyBecome a supporter of this podcast: https://www.spreaker.com/podcast/javascript-jabber--6102064/support.

NOW PLAYING

JSJ 399: Debugging with Async/Await with Valeri Karpov

0:00 1:03:48

No transcript for this episode yet

We transcribe on demand. Request one and we'll notify you when it's ready — usually under 10 minutes.

Over Engineered Chris Morrell A podcast where we explore unimportant programming questions (mostly PHP/Laravel/JavaScript) in extreme detail. BAT Community Podcast BAT Community & Brave Basic Attention Token (BAT) is a revolutionary digital advertising and rewards platform from the inventor of JavaScript and co-founder of Mozilla and Firefox that rewards users in Ethereum-based BAT tokens. Brave is a fast, BAT-powered privacy browser that blocks all 3rd-party ads and trackers by default. Learn more about BAT, Brave and tech with this podcast! JS Party: JavaScript, CSS, Web Development Changelog Media Your weekly celebration of JavaScript and the web. Current panelists: Jerod Santo, Kevin Ball (KBall), Nick Nisi, Chris Hiller, Amal Hussein & Amy Dutton.Past panelists: Suz Hinton, Feross Aboukhadijeh, Amelia Wattenberger, Divya Sasidharan, Alex Sexton, Rachel White, Emma Bostian, Ali Spittel, Mikeal Rogers & Jessica Sachs.We talk about the web platform (Chrome, Safari, Edge, Firefox, Brave, etc), front-end frameworks (ReactJS, SolidJS, Svelte, VueJS, AngularJS, etc), JavaScript and TypeScript runtimes (Node, Deno, Bun), web animation, SVG, TailwindCSS, robotics, IoT, and much more. If JavaScript and/or the web touch your life, this show’s for you.Some people search for JSParty and can't find the show, so now the string JSParty is in our description too. CodeWinds - Leading edge web developer news and training | javascript / React.js / Node.js / HTML5 / web development - Jeff Barczewski Jeff Barczewski The CodeWinds podcast is designed to help you keep up with the latest web developer news and techniques.Learn about the new developments in javascript, React.js, Node.js, HTML5 and other exciting web developer and mobile technologies.Listen to interviews and reviews of the latest and most promising new libraries, modules, and tools. Learn what the professional developers use to build their web and mobile web applications. Using the latest techniques and best practices you can continue to sharpen your skills.Each week Jeff Barczewski, a seasoned web developer and trainer will share his latest insights and will interview leaders in the web and mobile development community.Become your best, follow CodeWinds.
URL copied to clipboard!