# Javascript Promises with Martine Dowden

An episode of [.NET Rocks!](https://invisiblenetwork.ai/podcast/130068596), 27 Mar 2025, 53 min.

Audio: https://dts.podtrac.com/redirect.mp3/api.spreaker.com/download/episode/65115502/dotnetrocks_1943_javascript_promises.mp3

What are JavaScript promises, and why do you want to make them? Carl and Richard talk to Martine Dowden about all the various async options available in Javascript today, including Callbacks, Promises, Async/Await, and even ReactiveJS! Martine digs into some of the more remarkable features available, including grouping sync calls together so code is only called when they all complete, or the race option where only one needs to complete, and everything else is thrown away. Lots of power is available in Javascript today. Have you taken advantage of it?

## Transcript

[0:01] Speaker 1: How'd you like to listen to dot net rocks with
[0:03] Speaker 1: no ads? Easy? Become a patron for just five dollars
[0:07] Speaker 1: a month. You get access to a private RSS feed
[0:10] Speaker 1: where all the shows have no ads. Twenty dollars a month,
[0:14] Speaker 1: we'll get you that and a special dot NetRocks patron mug.
[0:18] Speaker 1: Sign up now at Patreon dot dot NetRocks dot com. Hey,
[0:34] Speaker 1: welcome back to dot net Rocks episode number nineteen forty three.
[0:39] Speaker 1: I'm Carl Franklin at amergri Gabel. How you doing, Richard?
[0:42] Speaker 1: What's up? I'm all right. This is weird to be
[0:45] Speaker 1: in the twentieth century of shows, but you know, yeah,
[0:48] Speaker 1: and so much happened during these years. Yeah, so we'll
[0:50] Speaker 1: talk about that in a minute. But uh, how's the
[0:53] Speaker 1: weather up there in otter Town? Yea, we gotta break today,
[0:57] Speaker 1: little suddy. You know it's it's definitely springtime. So yeah,
[1:01] Speaker 1: here too, things are changing.
[1:02] Speaker 2: We had one snowfall, which is kind of normal for
[1:05] Speaker 2: the coast, and now it's things are warming.
[1:07] Speaker 1: Up here too, and it's kind of nice. Yeah. I
[1:10] Speaker 1: install the camera right outside the studio nice and brought
[1:15] Speaker 1: the big screen TV and from the living room, which
[1:17] Speaker 1: we don't really use anymore and sort of mounted it
[1:20] Speaker 1: right in back of where the camera is, so I
[1:22] Speaker 1: have like a digital window out on my outside.
[1:25] Speaker 2: But you can control the amount of light, and so
[1:28] Speaker 2: you got control over your space till right, Yeah, exactly.
[1:31] Speaker 1: So it's fun. All right, it's good. Let's talk about
[1:33] Speaker 1: nineteen forty three before we do better. No framework going
[1:36] Speaker 1: to do that first, sure, all right, Well, from what
[1:38] Speaker 1: I know and what I read, nineteen forty three, the
[1:40] Speaker 1: tide of World War two began to turn against the
[1:43] Speaker 1: Axis powers, with significant events including the Soviet victory at
[1:47] Speaker 1: the Battle of Stalingrad, the Allied invasion of Sicily, and
[1:51] Speaker 1: the beginning of the Warsaw Ghetto uprising. The word ghetto
[1:56] Speaker 1: comes from Poland. Not a lot of people know that
[1:59] Speaker 1: in America anyway. And what's crazy when you go to
[2:01] Speaker 1: Warsaw is the chunks of it that are still there. Yeah,
[2:04] Speaker 1: the Polish are taken very seriously the ownership of those buildings,
[2:08] Speaker 1: and well, it's entirely likely there's no one left alive
[2:10] Speaker 1: that owned some of those buildings. They just won't do
[2:12] Speaker 1: anything about it. Yeah, they're holding off on the chance
[2:15] Speaker 1: that they could find some relations to the point now
[2:17] Speaker 1: where they've built these protective screens up one floor over
[2:21] Speaker 1: the sidewalk because there's Yeah, it's the building falling off.
[2:24] Speaker 1: They don't want to hurt anybody. Wow, there's still billet
[2:26] Speaker 1: holes in buildings in Warsaw from that. At that time,
[2:30] Speaker 1: Zootsuit riots happened in Los Angeles. White servicemen and police
[2:34] Speaker 1: officers attacked Mexican American youth, which turned that into the
[2:38] Speaker 1: Zootsuit riots. The Harlem race Riot occurred in Harlem, New
[2:42] Speaker 1: York after a white police officer shot in African American soldier.
[2:46] Speaker 1: In the good News section of nineteen forty three, the
[2:50] Speaker 1: Pentagon is completed, the Chinese exclusion acts are repealed. Actually
[2:54] Speaker 1: is that good news? Does sound like it? I'm not
[2:56] Speaker 1: so sure. But also two things were invented in nineteen
[3:00] Speaker 1: forty three that we need to thank the people for
[3:04] Speaker 1: duct tape, nice and LSD.
[3:07] Speaker 2: It's funny also when the Colossus computer, which arguably is
[3:13] Speaker 2: the first electronic programmable computing device, of course, built Blenchley
[3:20] Speaker 2: Park for cryptanalysis. Wow, although that's also the same. Forty
[3:24] Speaker 2: three is a year where the contract for ANIAC starts,
[3:27] Speaker 2: but they won't get finished until forty five.
[3:29] Speaker 1: Yeah, and I don't know.
[3:31] Speaker 2: This is also forty three was the era of the
[3:33] Speaker 2: first generation of antibiotics.
[3:35] Speaker 1: That's right.
[3:36] Speaker 2: Yeah, yeah, so, and there's some funny stories around that,
[3:39] Speaker 2: like they found the perfect bacterium for growing penicillin on
[3:46] Speaker 2: a cantalope.
[3:47] Speaker 1: I thought it was on an orange randomly. There were
[3:51] Speaker 1: are versions there, but the thing they call the golden mold,
[3:53] Speaker 1: it was actually on a canalope in Illinois. That's so cool,
[3:56] Speaker 1: and that maybe they already knew how to make penicill
[3:58] Speaker 1: at that point. But it became the master mechanism destructimyas
[4:02] Speaker 1: and was developed in forty three. I think that it
[4:05] Speaker 1: was really released in forty four, wasn't it.
[4:07] Speaker 2: Yeah, but that's when it was first developed and it
[4:10] Speaker 2: was the first treatment for tuberculosis.
[4:13] Speaker 1: Wow, take a lot of that stuff for granted, now,
[4:15] Speaker 1: don't we We share doom to the point where people forget. Yeah,
[4:18] Speaker 1: we used to have friends that died. He stepped on
[4:20] Speaker 1: a nail. You were going to die? Yeah, and you
[4:23] Speaker 1: everybody had somebody who died in tuberculosis. Many people oculosis.
[4:27] Speaker 1: It was untreatable, tetanus too. Yeah. Okay, so let's get
[4:31] Speaker 1: to better know a framework, roll the music. Awesome, A man,
[4:42] Speaker 1: what you got? This one comes from our friend Damian Edwards.
[4:45] Speaker 1: You know him. He's overdue for a show, isn't name?
[4:48] Speaker 1: We should totally is. Yeah, we need a little signal,
[4:51] Speaker 1: our reminiscence and all that good stuff. So he wrote
[4:56] Speaker 1: this tool. It's on GitHub called dot net purge. It's
[5:00] Speaker 1: a dot Net tool that runs dot net clean for
[5:02] Speaker 1: each target, framework and configuration and then deletes the output directories. Okay.
[5:07] Speaker 1: Can be run in a directory containing a solution or
[5:10] Speaker 1: project file because you know what disk space is low. No,
[5:13] Speaker 1: I'm kidding. I'm kidding, of course, Damien. That's not the point.
[5:17] Speaker 1: The point is you have all these dangling frameworks and
[5:21] Speaker 1: tools that you don't need anymore. Yeah, why confuse the issue?
[5:25] Speaker 1: Just clean them up, Just tidy stuff up. Yeah, so
[5:28] Speaker 1: that's cool. As you can see, it's a it's a
[5:31] Speaker 1: dot net tool. It's a command line thing. You can
[5:33] Speaker 1: add it to Windows Explore. There's a little registry hack
[5:37] Speaker 1: that you can add dot net purge to Explore a
[5:40] Speaker 1: context menu. Turn it into a shortcut. Yeah, very cool.
[5:43] Speaker 1: You know, at least it'll it'll it'll help with your
[5:45] Speaker 1: large lene you're programming large language model lature is not
[5:48] Speaker 1: navigating old files. Ooh, there you go. Yeah. And also
[5:52] Speaker 1: Simon Crop was a contributor to that. There's Damien and
[5:56] Speaker 1: Simon basically another guy you should probably be back on
[5:58] Speaker 1: the show. Yeah, so there you go. Clearly they both
[6:01] Speaker 1: had the problem and decided to fix it. Yeah. Maybe
[6:04] Speaker 1: it only happens in Australia, though I don't know. I
[6:06] Speaker 1: don't know the answer. Okay, he's talking to us today.
[6:10] Speaker 1: Richard grabbed a comment on a show eighteen eighty five,
[6:12] Speaker 1: the one we did with Martine back in February of
[6:14] Speaker 1: twenty four. We were talking about improving your CSS skills. Yeah,
[6:18] Speaker 1: and Vladimir Jirgov commented this about a year ago. Hees hi, guys,
[6:22] Speaker 1: long term listening to the show, writing in reference to
[6:24] Speaker 1: using chat GPT for creating CSS code. I found this
[6:28] Speaker 1: comment hilarious because it was a year ago when we
[6:31] Speaker 1: just didn't know. I've recently used the free version of
[6:34] Speaker 1: chat gpt for a small CSS h schmael and JavaScript project. Well,
[6:38] Speaker 1: I could say it's pretty good perspectives matter.
[6:40] Speaker 2: I'm an infrastructure engineer recently turned web developer, so my
[6:43] Speaker 2: appraisal of quote good CSS code is limited. Nevertheless, chat
[6:48] Speaker 2: GPD was able to produce clear, readable, almost eighty percent
[6:51] Speaker 2: accurate code. The other twenty percent I compensated by pointing
[6:54] Speaker 2: me to the right direction to fix it or just
[6:55] Speaker 2: it when I couldn't do it itself.
[6:57] Speaker 1: All this is good. It really blew me away a positively.
[7:00] Speaker 1: When I asked to refactor the code, it gave me
[7:02] Speaker 1: clear and concise, simplified Yeah, and ask it to comment
[7:06] Speaker 1: it as well, that's another trick. Yeah. Well, and again,
[7:09] Speaker 1: imagine this is a year ago, like so much has
[7:13] Speaker 1: happened in this space in a year. That's the problem
[7:16] Speaker 1: I find with chatchipt and things like CSS, because there's
[7:20] Speaker 1: so many posts like on stack overflow of people who
[7:23] Speaker 1: are posting bad CSS right and saying why is in
[7:27] Speaker 1: this work? And then their discussions and by the time
[7:29] Speaker 1: you get to the to the good one, you know,
[7:32] Speaker 1: to the solution, it might be three years old. And
[7:35] Speaker 1: so there's just a lot of confused CSS on the internet.
[7:41] Speaker 1: So I'm probably true for all code. But in general,
[7:44] Speaker 1: these tools have moved so quickly, and being aware that
[7:48] Speaker 1: we're coming up on a bills and there's some interesting
[7:50] Speaker 1: announcements coming, like you know, Microsoft's a tooling company first
[7:53] Speaker 1: and foremost, so expect amazing things in this space.
[7:57] Speaker 2: Yep, that's for sure, Vladimir, Thank you so much for
[7:59] Speaker 2: your comment, and a copy of music Cobey is on
[8:01] Speaker 2: its way to you. And if you'd like copy music Cobey,
[8:03] Speaker 2: I write a comment on the website at dot at
[8:04] Speaker 2: rocks dot com or on the facebooks. We publish every
[8:07] Speaker 2: show there and if I comment there or if you
[8:09] Speaker 2: comment there and I read it on the show, we'll
[8:10] Speaker 2: send you copy of music go bay.
[8:11] Speaker 1: And of course music to Code by born of a
[8:14] Speaker 1: conversation that we had on dot net rocks and it
[8:19] Speaker 1: turns out that music at a certain with certain attributes
[8:23] Speaker 1: really help you focus, and it's based on science. Was
[8:27] Speaker 1: that Dan North or was it Mark Semen? Mark Semen?
[8:30] Speaker 1: Was Mark Semen? Yeah? Yeah, So you know, we just
[8:32] Speaker 1: did track twenty two. So you can get that track
[8:35] Speaker 1: by itself, or you can get MP three flak or
[8:39] Speaker 1: wave collections. Go to music to Code by dot net. Okay, awesome,
[8:43] Speaker 1: Let's bring back Martine Dowdin, an award winning CTO ux
[8:49] Speaker 1: UI designer and developer, International speaker and author. Martin focuses
[8:54] Speaker 1: on web interfaces. That are beautiful, functional, accessible, and usable.
[9:00] Speaker 1: She approaches user experience from both art and science, drawing
[9:03] Speaker 1: from her degrees in psychology and visual communications. Martin has
[9:06] Speaker 1: worked as a developer, artist, educator, and consultants since two
[9:10] Speaker 1: thousand and five. Currently, she's the CTO at Andromeda Galactic
[9:15] Speaker 1: Solutions good name where she that's a great name as
[9:19] Speaker 1: opposed to like Minutia Incorporated right where she continues to
[9:25] Speaker 1: learn work on. Sorry, I didn't mean to make you laugh,
[9:29] Speaker 1: continues to learn work on and share her passion for
[9:32] Speaker 1: front end development. Welcome back, Martin.
[9:34] Speaker 3: Well glad to be back. Thank you for having me.
[9:36] Speaker 1: Sure.
[9:36] Speaker 2: Yeah, it's great to have you back, and I'm happy
[9:39] Speaker 2: to not be talking about CSS this time around. Not
[9:41] Speaker 2: that your conversation CSS aren't brilliant. Yeah, but admittedly I
[9:45] Speaker 2: think I pinged you saying it's been about a year
[9:48] Speaker 2: and I had been poking through your sessionized and saw
[9:51] Speaker 2: you doing a talk on promises and I'm like, you know,
[9:56] Speaker 2: those things have driven me crazy since they were first
[9:58] Speaker 2: talked about in the W three C.
[10:01] Speaker 1: I should talk to Martina.
[10:03] Speaker 2: It's like, as soon as I get that urge, like
[10:04] Speaker 2: I want to call you and talk about it we
[10:05] Speaker 2: should probably make a show.
[10:10] Speaker 1: So, Martine, what is on your mind these days?
[10:13] Speaker 3: Well, the I've been writing blog posts and one of
[10:17] Speaker 3: them that you mentioned was about promises and also made
[10:20] Speaker 3: it as a talk, and so I realized when I
[10:24] Speaker 3: was I was, I've been working with some junior devs
[10:27] Speaker 3: and some dot devs recently, and uh, we were arguing about,
[10:31] Speaker 3: you know, better ways to write code and how something
[10:33] Speaker 3: should be architected, because you know, de've never disagree on
[10:36] Speaker 3: such things.
[10:37] Speaker 1: Never, never, never, never.
[10:40] Speaker 3: And I realized that one one of the one of
[10:44] Speaker 3: the guys I was talking to, didn't actually understand what
[10:48] Speaker 3: promises did or how they worked. And so that's kind
[10:52] Speaker 3: of what prompted me to write that article because as
[10:55] Speaker 3: I did some digging, I realized that not only do
[10:58] Speaker 3: it's not as common knowledge as I originally thought it
[11:01] Speaker 3: was on how they work, but also that there's so
[11:04] Speaker 3: much with them that can be done that like, sure
[11:07] Speaker 3: people can remember how to do a dot then or
[11:10] Speaker 3: dot catch or maybe even in a sink away, but
[11:12] Speaker 3: there's so much more to them than those three things,
[11:14] Speaker 3: which is kind of what a lot of people think
[11:16] Speaker 3: of when they think promises, Right, you get your fetch
[11:18] Speaker 3: you get your then and go on and go forth
[11:20] Speaker 3: and conquer. But there's a lot more to it that
[11:22] Speaker 3: you can do in terms of parallelization or how you
[11:26] Speaker 3: want things to happen, or if you want, you know,
[11:28] Speaker 3: just give me the first response or things like that.
[11:30] Speaker 3: And so that's kind of what prompted me to write it.
[11:33] Speaker 1: And just to back up, we're talking about JavaScript here,
[11:35] Speaker 1: yes we are. You know, we didn't really introduce the
[11:38] Speaker 1: topic unless you read the title of the show, but
[11:41] Speaker 1: so we're talking JavaScript promises, and you know this is
[11:44] Speaker 1: the way to do one way to do things asynchronously.
[11:47] Speaker 1: Right you mentioned a sink a weight, which we do
[11:50] Speaker 1: and c sharp all the time, but turned into JavaScript as.
[11:54] Speaker 3: Well, yep, which is it's kind of cool. I just
[11:57] Speaker 3: I mean, the thing with them is the I found
[11:59] Speaker 3: that the ear handling becomes a little different if you're
[12:02] Speaker 3: doing the a a sek away where you have to
[12:04] Speaker 3: wrap the trycatch and so on, and then depending if
[12:07] Speaker 3: you want to where you want to catch your things
[12:09] Speaker 3: and how ends up being a little bit different. But oh,
[12:12] Speaker 3: in all, I find they I personally like it because
[12:15] Speaker 3: I find it more readable to just be able to go,
[12:17] Speaker 3: you know, especially if you have multiple private promises you're
[12:19] Speaker 3: doing in sequence to just be able to do a
[12:22] Speaker 3: weight one A wait two, a wait three, And it's
[12:24] Speaker 3: really instead of having to do the whole that then
[12:27] Speaker 3: that then that then that then I find it less worthy,
[12:30] Speaker 3: but it's a personal preference really.
[12:32] Speaker 1: So the whole dot then that that is that the
[12:34] Speaker 1: promise syntax like fluent. Is that how it works.
[12:37] Speaker 3: Yeah, So in JavaScript, fetch is a promise. I'm just
[12:41] Speaker 3: going to use that as the example because it's the
[12:43] Speaker 3: same one I have in the in the article. But
[12:45] Speaker 3: you would do like fetch whatever the U R L, right,
[12:48] Speaker 3: and then you would do after that you do dot
[12:51] Speaker 3: then and then you're going to get the results and
[12:53] Speaker 3: that that's that's going to be a function. So you
[12:55] Speaker 3: get your result and you can do whatever you want
[12:58] Speaker 3: with that result at that point, right, And you can
[13:00] Speaker 3: chain those dot dens, so if you get what you
[13:02] Speaker 3: sometimes see is like where it starts, people try to
[13:06] Speaker 3: nest the dot dens instead of chaining them, so you
[13:08] Speaker 3: get kind of that that Christmas tree pattern like that,
[13:13] Speaker 3: but you can just know and the fun thing with
[13:16] Speaker 3: that then and it doesn't actually require you to return
[13:19] Speaker 3: a promise. You can put promise one that then promise
[13:22] Speaker 3: you know, take my results and then put it in
[13:24] Speaker 3: for promise too and so on. But you can very easily,
[13:28] Speaker 3: very easily just do some kind of transformation on the
[13:31] Speaker 3: data and return that site. Once you're in that that
[13:34] Speaker 3: then sequence. It does not have to be a promise.
[13:37] Speaker 3: You can do then whatever you want to after that.
[13:40] Speaker 1: At that point it kind of sounds like a task
[13:43] Speaker 1: and see sharp the concept anyway, where you know, when
[13:47] Speaker 1: you have a promise, what do you do with it? Right?
[13:50] Speaker 1: That's yeah.
[13:52] Speaker 3: For JavaScript, the most common use would be for like
[13:57] Speaker 3: fetching data, like whether whether it's whether you're doing using
[14:01] Speaker 3: a framework or something or you're just doing raw JavaScript.
[14:05] Speaker 3: Most of the time it's because you're fetching data that's
[14:08] Speaker 3: ninety nine percent of the timeline, it's going to be
[14:10] Speaker 3: four and.
[14:10] Speaker 1: You're trying not to hang the UI.
[14:12] Speaker 2: Why you do it right that I send off the
[14:15] Speaker 2: fetch you can.
[14:16] Speaker 3: It doesn't matter that more depends on how you're calling
[14:21] Speaker 3: the function more than more and where more than the
[14:25] Speaker 3: fact that it's a promise. The other one would be
[14:27] Speaker 3: to turn that I use it a lot for is
[14:29] Speaker 3: to turn callbacks into a promise because they're easier to
[14:34] Speaker 3: chain and handle and deal with. I find so like
[14:38] Speaker 3: when you're doing an image upload or a file upload
[14:41] Speaker 3: and you want to do a preview for it, there's
[14:43] Speaker 3: the whole file reader thing, and that's always a that's
[14:46] Speaker 3: one of the common ones, or even the set time
[14:47] Speaker 3: out technically speaking, you know, is callback. So like those
[14:50] Speaker 3: sorts of things so that I can chain them easily
[14:53] Speaker 3: with other things. I'll tend to turn them into promises
[14:56] Speaker 3: because it makes my life a whole lot easier than
[14:59] Speaker 3: living in and trying to figure out which callback is
[15:02] Speaker 3: doing what and going where. And I find them gross personally,
[15:05] Speaker 3: But just.
[15:07] Speaker 1: A just a for full disclosure, It's been a long
[15:11] Speaker 1: time since I've looked at that kind of complexity in JavaScript.
[15:14] Speaker 1: I mean, ever since I found Blazer, I've been as
[15:18] Speaker 1: much c Sharp as possible and as little JavaScript as possible,
[15:21] Speaker 1: And usually the JavaScript that I'm calling is just something
[15:24] Speaker 1: to get something from the dom that I can't get
[15:27] Speaker 1: with sea Sharp.
[15:28] Speaker 3: Yeah, dumb manipulation doesn't have too much in terms of
[15:32] Speaker 3: callbacks or anything else. They have a couple, I guess,
[15:35] Speaker 3: especially when you're getting to events like.
[15:38] Speaker 1: Yeah, window do resize all that stuff.
[15:41] Speaker 3: Or even what a fun one. That's always a h
[15:44] Speaker 3: Be careful how you type that in your Google searches
[15:47] Speaker 3: everything related to drag and drop because dom drag events
[15:52] Speaker 3: can can make some fun fun Oh yeah, fun search
[15:55] Speaker 3: results if you're not careful.
[15:56] Speaker 1: Oh boy, yep, Tom drag pictures of Dom Delawi's. So
[16:04] Speaker 1: does the fetch approach have an advantage when you want
[16:07] Speaker 1: to call off like multiple data sets you want to
[16:09] Speaker 1: fetch and you don't really care what order they come
[16:11] Speaker 1: back in you're populating different divs kind of thing. Yes,
[16:14] Speaker 1: if that word shines.
[16:16] Speaker 3: So fetch literally just goes and gets the data. So
[16:20] Speaker 3: if you wanted to call multiples, what you might do
[16:23] Speaker 3: is do it in a You could do a promise
[16:26] Speaker 3: that all which you would put a series of fetches
[16:29] Speaker 3: in it, and it would only return the data once
[16:32] Speaker 3: all of them have returned.
[16:33] Speaker 1: That's convenient.
[16:35] Speaker 3: So if you had to get if you needed all
[16:37] Speaker 3: three sets of data in order to populate or do
[16:41] Speaker 3: whatever you were going to do, that wouldn't return until
[16:43] Speaker 3: all of them have returned. Now, the downside is if
[16:46] Speaker 3: one of it fails, it fails everything. So that can
[16:48] Speaker 3: be good or bad, right, It depends on your use case,
[16:51] Speaker 3: but it.
[16:51] Speaker 2: Is nice if you do need three sets and you
[16:53] Speaker 2: don't want to wait for each one to come back,
[16:55] Speaker 2: to do it that way and they run in parallel
[16:57] Speaker 2: and once they're all back, then you act. If you
[17:00] Speaker 2: got three different sets that just render in three different
[17:02] Speaker 2: dips and you don't care whatever that comes in, can
[17:04] Speaker 2: you still use it?
[17:05] Speaker 3: Then you would probably do three. You would do either
[17:10] Speaker 3: three functions or three fetches, and then in the response
[17:13] Speaker 3: from the that fetch. But what I wouldn't do is
[17:15] Speaker 3: try to go a sink a wait for a second
[17:18] Speaker 3: and third because then you're literally waiting for a second
[17:20] Speaker 3: and third. Right, So at that point I would probably
[17:22] Speaker 3: do either separated into three functions that I would call
[17:25] Speaker 3: and not wait on right, or if I wanted everything
[17:29] Speaker 3: in the same function, I would do, uh, fetch a dot,
[17:32] Speaker 3: then do whatever I'm gonna do, fetch b dot, then
[17:35] Speaker 3: do what I'm going to do and do it as
[17:36] Speaker 3: a dot. Then structure, because then they're not waiting on
[17:39] Speaker 3: each other because JavaScript is going to fire the first one,
[17:42] Speaker 3: the second one, the third one because it has the dot.
[17:45] Speaker 3: Then it's not waiting for that to be finished. It's
[17:47] Speaker 3: just going to fire and go and move on to
[17:49] Speaker 3: the next but it will wait. Where it will wait
[17:53] Speaker 3: is to do what's in that dot then then I'll
[17:57] Speaker 3: wait for that data to come in. So if I
[17:59] Speaker 3: wanted them in peril, well, i'd probably use and in
[18:01] Speaker 3: the same function, I'd use dot then and definitely not
[18:04] Speaker 3: a sync away because then you're forcing for the way.
[18:06] Speaker 1: How is one doesn't help that there's multiple JavaScript async
[18:10] Speaker 1: methods like call there's callbacks, there's promises, there's a sync away.
[18:16] Speaker 1: Is that all of them?
[18:17] Speaker 3: Well, if you get into some of the frameworks like
[18:19] Speaker 3: our XGS, and you have the entire observable game as well.
[18:22] Speaker 2: React right, yeah, yeah, then is what the other frames
[18:26] Speaker 2: will provide you on top of everything else.
[18:28] Speaker 3: And then there's a handful of listeners too, which I
[18:31] Speaker 3: think are just callbacks if I remember, well.
[18:34] Speaker 1: How does one do a resilient strategy like we do
[18:36] Speaker 1: with poly in c sharp, Like you know, if if
[18:40] Speaker 1: a service is down and you call it, how can
[18:43] Speaker 1: you do like easing, you know, back off multiple retries
[18:48] Speaker 1: that kind of thing. Is there such a thing like
[18:51] Speaker 1: that built into JavaScript?
[18:53] Speaker 3: So our XGS does have a if you're dealing with observables,
[18:57] Speaker 3: does have a retry function. But you can fairly easily
[19:01] Speaker 3: do or retribe, because what you're gonna you're gonna utilize
[19:04] Speaker 3: your catch for that, right, So we're either going to
[19:06] Speaker 3: do in a trycatch block or as a dot catch
[19:09] Speaker 3: you're gonna say, you're going to have a variable outside
[19:11] Speaker 3: of that how many times have I retried? And then
[19:14] Speaker 3: you can call itself again and increment your retry.
[19:17] Speaker 4: Right.
[19:18] Speaker 3: The other thing you can do in your catch is say, okay,
[19:20] Speaker 3: this one's down, give me a different one. There's promise
[19:24] Speaker 3: not all settled that you can use. So if you
[19:27] Speaker 3: have like say, three three different APIs that you want
[19:30] Speaker 3: to hit, but you know that one of them is
[19:32] Speaker 3: likely to fail. But if you can get the data, great,
[19:35] Speaker 3: If not, we'll move on, it's okay, situation. Or if
[19:39] Speaker 3: you want to handle depending on let's say you've got
[19:42] Speaker 3: your three calls, but you want to handle your failures
[19:44] Speaker 3: a little bit differently, you can do and all settled.
[19:46] Speaker 3: So what happens with the all settled is like, let's
[19:49] Speaker 3: say one of your three of them dies in the middle, right,
[19:52] Speaker 3: Unlike the promise at all, which goes ahead and and
[19:55] Speaker 3: will throw an error if any of them fail. What
[19:58] Speaker 3: they all settled does is it will return for all
[20:01] Speaker 3: three a status of either okay or there's been an error,
[20:06] Speaker 3: and then if there's an error reason so you can
[20:08] Speaker 3: get you can still get your data for say like
[20:10] Speaker 3: one in two and then you'll get your error for three.
[20:13] Speaker 3: But then you have to make sure in your once
[20:15] Speaker 3: you get the data that you realize that it's not
[20:17] Speaker 3: just the raw data. It's got like the value and
[20:20] Speaker 3: the status or the value or the status in error
[20:23] Speaker 3: depending on So you've got to remap that to whatever
[20:26] Speaker 3: you need. But that one's convenient if you have a
[20:29] Speaker 3: service that you know is maybe a little flaky, that
[20:32] Speaker 3: might but you still want to do whatever you're going
[20:34] Speaker 3: to do with the rest of the data, or if
[20:36] Speaker 3: you're okay with only partial information. That's one that's that's
[20:40] Speaker 3: pretty useful for that.
[20:41] Speaker 1: Yeah, yeah, you were talking about this.
[20:42] Speaker 2: Some of these more advanced features in jabscript promises like
[20:46] Speaker 2: all settled that this is where you get some power.
[20:49] Speaker 3: Yeah. The other one if you know you've got that's
[20:52] Speaker 3: that's part that I find particularly powerful. The only use
[20:55] Speaker 3: case I've ever really seen it used for networking type
[20:58] Speaker 3: of stuff, but is the race and where it's like
[21:04] Speaker 3: you just want the first one that can get me
[21:06] Speaker 3: an answer, get me that one nice. So you can
[21:09] Speaker 3: put like, let's say one, two, and three in there,
[21:12] Speaker 3: and once one of them fires, you're good. You've got
[21:14] Speaker 3: an answer. You run with it, right, and it's going
[21:16] Speaker 3: to give up on the other two, right, So from
[21:18] Speaker 3: a speed perspective, that's super nice.
[21:20] Speaker 2: Whether they come back or not, you're just going to
[21:22] Speaker 2: ignore the results, right. So, yeah, you've got multiple services
[21:26] Speaker 2: that can bring you the result. You just want the
[21:27] Speaker 2: fastest one.
[21:28] Speaker 3: Yeah, Now, raise will if one of them fails, it
[21:32] Speaker 3: will fail out the same way as promised at all.
[21:34] Speaker 3: If you do promise that any it will try until
[21:37] Speaker 3: it gets an answer, it will give you the fastest
[21:39] Speaker 3: answer that hasn't failed, and it won't fail until all
[21:42] Speaker 3: of them has failed. So if you really want, just
[21:44] Speaker 3: give me whatever as fast as humanly possible, ignore all
[21:48] Speaker 3: failures unless everything fails, obviously, but it's promised that any
[21:52] Speaker 3: which is kind of really powerful. I have not found
[21:55] Speaker 3: a use case for that one yet, but one day,
[21:58] Speaker 3: one day, I.
[21:59] Speaker 2: Will literally are you know, calling three different services from
[22:03] Speaker 2: three different places that are going to provide the same result,
[22:06] Speaker 2: and any of them will do.
[22:07] Speaker 1: And I don't care if any of them fail as
[22:09] Speaker 1: long as one of them doesn't, right, sure exactly. Yeah,
[22:11] Speaker 1: it's nice. Yeah, that is powerful. It's powerful and a
[22:14] Speaker 1: bit weird, but you know, well strange. I mean, I'm
[22:16] Speaker 1: thinking about the alternatives. The alternative is using sort of
[22:19] Speaker 1: round robin dns. You know, if you've got like three
[22:22] Speaker 1: services that are all trying to share the load or whatever.
[22:25] Speaker 1: But what you're doing is you're hitting all three of
[22:27] Speaker 1: them all at the same time rather than a round robin,
[22:30] Speaker 1: So may put a little more load on the network,
[22:33] Speaker 1: but you at least get the result that you want.
[22:36] Speaker 4: You know.
[22:36] Speaker 1: Yeah, first, first person to give me a chicken sandwich,
[22:40] Speaker 1: I'll eat it.
[22:41] Speaker 3: The other actually, the one of the US because I
[22:43] Speaker 3: could think for that would be if you're calling something
[22:45] Speaker 3: like from a CDN, so you could call multiple CDMs
[22:48] Speaker 3: so that if one of them is down right.
[22:50] Speaker 2: Yeah, yeah, sure you do want that any sense, because
[22:54] Speaker 2: I don't care if there's a failure as long as
[22:56] Speaker 2: there's one that.
[22:56] Speaker 3: Doesn't fail, right exactly.
[22:58] Speaker 1: Yeah, that's what's important. But you do have to throw
[23:01] Speaker 1: the other two chicken sandwiches away, I mean, there isn't
[23:04] Speaker 1: if they if you're.
[23:04] Speaker 3: Goin of like, well it would I'd have to double
[23:09] Speaker 3: check the network. But the network calls from the browser,
[23:11] Speaker 3: but I think it actually abandons the network call, like
[23:13] Speaker 3: it terminates.
[23:15] Speaker 1: If it always drops the connection. Well, that's good.
[23:17] Speaker 3: I think I'd have to double check that, and it
[23:20] Speaker 3: might that might even be browser specific, so that that
[23:23] Speaker 3: would be don't quote me on that one, because I'd
[23:26] Speaker 3: have to actually.
[23:26] Speaker 1: Look at that, But that would be smart. That would be,
[23:29] Speaker 1: you know, in a perfect world.
[23:30] Speaker 3: In a perfect world. Yeah, because the Internet is perfect,
[23:33] Speaker 3: it has yeah never never, and JavaScript is perfect, it
[23:37] Speaker 3: has no flaws.
[23:38] Speaker 1: It's the best language ever.
[23:42] Speaker 3: It was totally thought through when it was created, right.
[23:45] Speaker 1: Oh, definitely. I think it took a weekend, right, So
[23:50] Speaker 1: let's yeah, Well, let's talk about some challenges when approaching
[23:57] Speaker 1: acink JavaScript programming for the first time. What are people
[24:02] Speaker 1: getting hung up on?
[24:04] Speaker 3: One of the common one of the common things I've
[24:07] Speaker 3: seen when I'm teaching people how to use promises is
[24:12] Speaker 3: they'll learn a pattern and they'll try to use it everywhere,
[24:14] Speaker 3: no matter what. And I don't think this is specific
[24:17] Speaker 3: to promises.
[24:18] Speaker 1: Here's your hammer, find the nails exactly.
[24:22] Speaker 4: They'll learn I go.
[24:23] Speaker 3: Let's say they'll learn a sink await right, and they
[24:25] Speaker 3: will regardless of whether it needs to be parallel or not.
[24:28] Speaker 3: They'll just like await everything right. And so I mean,
[24:32] Speaker 3: in the end it works, and this is the piece. Right,
[24:35] Speaker 3: in the end, it works if even if you need
[24:37] Speaker 3: it technically to have them in parallel, you await everything
[24:41] Speaker 3: you you're gonna you're gonna take a performance hit, but
[24:44] Speaker 3: it'll work. Right. So I think those are the most
[24:48] Speaker 3: probably nefarious things because it's.
[24:51] Speaker 1: Not like it's broken, and we have the same problems
[24:54] Speaker 1: sea sharp Right. Once you learn a sync awight, you
[24:57] Speaker 1: want to do everything a sink and don't necessarily need
[25:01] Speaker 1: to a perfect example of this is data access right.
[25:06] Speaker 1: Data access can be completely done with adeo dot net,
[25:10] Speaker 1: which is sort of the lingua franca of dot net,
[25:14] Speaker 1: sql access or whatever, and it can all be done synchronously,
[25:19] Speaker 1: and it should be done synchronously because there isn't any
[25:21] Speaker 1: reason not to. When you add a sync to it,
[25:27] Speaker 1: even though you're not using it now, you're requiring the
[25:30] Speaker 1: method that calls it to be a sync. So property
[25:33] Speaker 1: getters and setters become more difficult, you know, just standard
[25:39] Speaker 1: events that aren't marked a sync that you don't want
[25:41] Speaker 1: to mark a sync that kind of stuff. So, yeah,
[25:44] Speaker 1: we have the same problem over here.
[25:45] Speaker 3: The other one I see, which is again is a
[25:49] Speaker 3: little bit more advanced, but it's the trying to mix
[25:52] Speaker 3: and match two things and make them work well together.
[25:55] Speaker 3: So like not realizing that you can fairly easily transform
[26:00] Speaker 3: a call back into a promise and then trying to
[26:03] Speaker 3: mix your callbacks and your promises and ending up in
[26:05] Speaker 3: some weird, kind of weird Christmas tree jumbold mess because
[26:10] Speaker 3: you're trying to mix the two or same with So
[26:14] Speaker 3: if you're using RXGS and you're using observables in an
[26:18] Speaker 3: RXGS chain, so let's say you have your first you know,
[26:22] Speaker 3: you get your your calling, your observable you get, and
[26:25] Speaker 3: then you're going to do a pipe with your maps
[26:27] Speaker 3: and your switch maps and your all of those things.
[26:30] Speaker 3: You can actually return as part of a switch map
[26:32] Speaker 3: a promise instead of an observable, and it'll take it
[26:35] Speaker 3: like a champion on the output return and observable. So
[26:39] Speaker 3: that's kind of but what I see is people not
[26:41] Speaker 3: realizing that they can do that and that that promise
[26:45] Speaker 3: as long as you're starting with an observable in RXGS,
[26:49] Speaker 3: you can stick and promise in the middle or call
[26:51] Speaker 3: that's actually to a promise in the middle, and it's fine,
[26:54] Speaker 3: and it'll take it. I mean, you're going to get
[26:57] Speaker 3: a one time value. It's not going to be a stream,
[27:00] Speaker 3: but it'll it'll work. And so I see some weirdnesses
[27:04] Speaker 3: in trying to like shoehorn in various often very creative
[27:08] Speaker 3: ways the pieces together with not not quite understanding where
[27:13] Speaker 3: they line up and how you can either turn one
[27:16] Speaker 3: into the other or where chaining can just work and
[27:20] Speaker 3: doesn't have to. And the other big one is like
[27:23] Speaker 3: the Christmas train I talked about before, or instead of
[27:26] Speaker 3: dot venning as a chain, they just kind of start
[27:28] Speaker 3: nesting the dot bens forever and ever amen, which again
[27:31] Speaker 3: works but not ideal and hard to read.
[27:34] Speaker 1: Right right, did you say forever and ever amen? Yes,
[27:38] Speaker 1: Hodding Randy Travis, there, I saw what you did there.
[27:41] Speaker 1: All right, let's take a break and when we get back,
[27:44] Speaker 1: we got some more questions from our tin doubt and
[27:46] Speaker 1: we'll be right back. Don't go away. Did you know
[27:49] Speaker 1: you can easily migrate asp net web apps to Windows
[27:53] Speaker 1: containers on aws. Use the app to container tool to
[27:57] Speaker 1: containerize your iis websites and deploy to aws Managed Container
[28:02] Speaker 1: services with or without Kubernetes. Find out more about app
[28:07] Speaker 1: to container at aws dot Amazon dot com, Slash dot net,
[28:12] Speaker 1: slash modernize, and we're back. It's dot net rock some
[28:19] Speaker 1: Carl Franklin. That's my friend Richard Campbell. Hey there, Martin
[28:22] Speaker 1: dubtny is here. We're talking javascripts and let's see if
[28:26] Speaker 1: you don't want ads. By the way, if you don't
[28:28] Speaker 1: want to hear these breakads, you can become a patron
[28:30] Speaker 1: at Patreon dot dot Nerocks dot com five bucks a
[28:33] Speaker 1: month and we'll give you an ad free feed. Uh okay, Richard,
[28:35] Speaker 1: you had a question, then I want to I have
[28:37] Speaker 1: a question to change course. Yeah, well, just before the
[28:40] Speaker 1: break Martine should have just dropped RxJS in our laps.
[28:43] Speaker 1: I'm like, wait what yeah?
[28:45] Speaker 2: Uh, Because I always thought that the reactive extensions were
[28:47] Speaker 2: important before promises had been standardizing the browsers, like reactive
[28:51] Speaker 2: js came along like twenty fifteen, twenty sixteen, and we
[28:54] Speaker 2: didn't get uniformity on promises to like twenty twenty one,
[29:01] Speaker 2: so it seemed like rxchas's a safe way to go.
[29:03] Speaker 3: Right, it's fairly recently. Yeah, well they have very different purposes,
[29:08] Speaker 3: So okay, like, can you do similar that you? So,
[29:13] Speaker 3: let me back up with rxs and the concept of observables,
[29:17] Speaker 3: assuming it's not an and and I think observable, which
[29:21] Speaker 3: is a whole different ballgame. Let's let's muddel the two
[29:24] Speaker 3: while we're at it, because of course we can't but
[29:28] Speaker 3: an observable, whether it's just a dumb subject, a behavior subject,
[29:32] Speaker 3: or a replace subject, is going to be a stream, right.
[29:35] Speaker 3: Promises are one and done. So the fact that you
[29:39] Speaker 3: can mix and match the two and the fact that
[29:41] Speaker 3: you can kind of make both of them work together
[29:44] Speaker 3: is a nice city. But they have a very different
[29:49] Speaker 3: purposes in the grand scheme of things, Like if I
[29:52] Speaker 3: want to continue listening to something, I can't use it.
[29:55] Speaker 3: I mean, I can do things with promises, but like
[29:58] Speaker 3: I still have to have my listener versus the observable
[30:02] Speaker 3: with Once you subscribe to the observable, you're going to
[30:05] Speaker 3: get that stream until you unsubscribe. Of course, because everything
[30:09] Speaker 3: JavaScript has to be complicated, We're going to add the
[30:12] Speaker 3: async subject in the mix, which is a one and done,
[30:15] Speaker 3: which is an observable you subscribe to as if it
[30:17] Speaker 3: was any other of the observable types, which but it's
[30:21] Speaker 3: not going to fire off the result until it's completed,
[30:24] Speaker 3: so it'll only ever have that one value.
[30:26] Speaker 1: The way I think of reactive extensions is a way
[30:28] Speaker 1: to turn event handling in the classic sense, where you
[30:32] Speaker 1: have event listeners and you do something in the event
[30:35] Speaker 1: handler and just turn that into like you said, a
[30:37] Speaker 1: stream or something that you can query, hey, how many
[30:40] Speaker 1: times did this event occur? And quantify that and give
[30:42] Speaker 1: me the data that was passed in. And that came
[30:46] Speaker 1: really into sharp focus when we interviewed remember Bjorn and
[30:49] Speaker 1: the guys that did the helicopter whatever the drone programs
[30:56] Speaker 1: at NDC, and they wrote a little tool to handle
[31:00] Speaker 1: those because there's a lot of events that come right
[31:03] Speaker 1: when they when they're flying around and they're moving, and
[31:06] Speaker 1: they use the reactive extensions to to manage that, which
[31:11] Speaker 1: would be absolutely impossible trying to do it with event handlers,
[31:15] Speaker 1: timers and things. So anyway, that's that's my understanding of
[31:19] Speaker 1: the reactive kind of observable model.
[31:22] Speaker 3: The I think the most the most. There's kind of
[31:26] Speaker 3: two places I use it a lot. I'm from going
[31:30] Speaker 3: to use observables. I would say one of them is
[31:32] Speaker 3: I do tend to work a lot with Firebase and
[31:34] Speaker 3: Firebase as a real time database and the fire store.
[31:38] Speaker 3: But either way it's it's a real time situation, right,
[31:40] Speaker 3: So I can subscribe to my data, and as data
[31:45] Speaker 3: changes in the database, I'm just going to get the
[31:47] Speaker 3: latest and greatest directly so to me using this, you know,
[31:50] Speaker 3: using the their system. So that's one of the ways
[31:54] Speaker 3: where it's legitimately a stream that I'm you know, connected
[31:57] Speaker 3: to my database directly and I want to get that
[32:00] Speaker 3: stream now. Where that gets interesting, and then you have
[32:02] Speaker 3: to worry about, Okay, I'm piping this to a form
[32:04] Speaker 3: I maybe don't want my form values to go ahead
[32:07] Speaker 3: and update just because somebody else updated the data day.
[32:10] Speaker 3: So there's use cases where you have to start thinking, okay,
[32:12] Speaker 3: where do I want it feeding me the stream or
[32:15] Speaker 3: where do I want it to get the stream? Call
[32:18] Speaker 3: it a one and done, and you know there's there's
[32:20] Speaker 3: months is there. And the other piece is let's say
[32:25] Speaker 3: I have a piece of data in a service, right
[32:28] Speaker 3: that I'm keeping up to date so that I can
[32:30] Speaker 3: potentially send to multiple components or multiple places in might UI, right,
[32:34] Speaker 3: and it might be something local too. I don't know,
[32:37] Speaker 3: let's say it's a let's do the number of visitor
[32:41] Speaker 3: tickers something dumb, right, it doesn't matter what it is.
[32:45] Speaker 3: And so that would be something where I can feed
[32:47] Speaker 3: whatever the latest value is and any component Okay, I
[32:50] Speaker 3: usually use Angular a lot, so any component would go
[32:53] Speaker 3: ahead and you know, get that value an automatically update
[32:56] Speaker 3: and automatically do what it needs to do in the
[32:58] Speaker 3: UI and update the UI according or do some math
[33:01] Speaker 3: or whatever. But those are kind of the two places.
[33:04] Speaker 3: Is either for uy stay in terms of or maybe
[33:08] Speaker 3: turning something off and on and being able to listen
[33:10] Speaker 3: to an action happening anywhere and turn something off and on,
[33:13] Speaker 3: or like dark mode is a good example that way
[33:16] Speaker 3: doesn't matter where the button is and then or because
[33:20] Speaker 3: then I can have the button trigger the update and
[33:23] Speaker 3: then whatever's list switching over the theme is listening to
[33:26] Speaker 3: that to that observable or connected to the database. But
[33:30] Speaker 3: that's a little bit different. Then let's say your your
[33:34] Speaker 3: promises where it's like a one and done. Once it's done,
[33:36] Speaker 3: it's done. It's not there's no continual listening. But it
[33:39] Speaker 3: also means that when you're dealing with the observables, you
[33:41] Speaker 3: have to make sure to stop listening to them at
[33:44] Speaker 3: some point, because otherwise you end up with them. Yeah,
[33:46] Speaker 3: there's a cleanup step that now needs to happen, which
[33:49] Speaker 3: doesn't happen in promises because obviously there were when I'm done.
[33:52] Speaker 2: Okay, so I'm preeting pretty clear on our xas is
[33:56] Speaker 2: for observers connecting to streams and being able to react
[33:59] Speaker 2: to them accordingly. Yeah, maybe I'm not a clear on
[34:02] Speaker 2: where i'd use promises versus async a weight and JavaScript,
[34:05] Speaker 2: because you know, when I look at the rafts to
[34:07] Speaker 2: async a weight, they basically say, hey, this is making
[34:09] Speaker 2: promises nicer.
[34:10] Speaker 1: Yeah.
[34:11] Speaker 3: So yeah, so acync await is just is just a
[34:16] Speaker 3: uh a way to do promises. It's not changing anything.
[34:21] Speaker 3: It's just a how do you want to think of it?
[34:26] Speaker 3: Maybe grammar like how do you want to structure your promise?
[34:29] Speaker 3: That's all that's all it is to It doesn't change
[34:31] Speaker 3: anything about the functionality. It's not do I want to
[34:33] Speaker 3: use asink or promises? It's like I'm using promises and
[34:37] Speaker 3: do I want to write do I wanted to you know,
[34:40] Speaker 3: write it this way or that way? Essentially, that's all.
[34:42] Speaker 3: It's just a syntactic sugar at that point.
[34:44] Speaker 1: And you mentioned that you prefer using asnk a weight
[34:47] Speaker 1: because you can do everything line by line rather than
[34:51] Speaker 1: having dot the n's all over the place.
[34:53] Speaker 3: Yeah, I just it's but it's not going to be.
[34:56] Speaker 3: It's not I'm not going to be able to write
[34:57] Speaker 3: it that way for everything because of the wholeation we
[35:00] Speaker 3: were talking about earlier. Right, it depends on. But if
[35:03] Speaker 3: I'm doing very much A, then B, then C very
[35:06] Speaker 3: programmatically one two, three, four five, then I find it
[35:09] Speaker 3: a lot easier to to handle, especially if I really
[35:12] Speaker 3: don't care about error handling outside of it worked or
[35:15] Speaker 3: it failed like my function worker failed, in which case
[35:17] Speaker 3: I track at the block and I'm done, right.
[35:20] Speaker 1: And you still have access to the ane and all
[35:23] Speaker 1: settled and all that stuff, whether you're using the ACN
[35:27] Speaker 1: syntax or just the promise intex Yeah.
[35:29] Speaker 3: Oh yeah, yeah, because instead of doing promise dot all,
[35:33] Speaker 3: you know, my array of promises dot done, I would
[35:36] Speaker 3: do my results equals away promised dot all, my array
[35:41] Speaker 3: of promises essentially.
[35:43] Speaker 1: Right. Okay, a while ago before the break, you brought
[35:45] Speaker 1: up map, and I'm not so sure many of our
[35:49] Speaker 1: listeners know what that is in another one map switch
[35:52] Speaker 1: or maple switch up.
[35:55] Speaker 3: So those are all various RXGS functions that do various things.
[35:59] Speaker 3: So in our which is okay, so map, there's your
[36:02] Speaker 3: XGS map and then there's map in terms of mapping
[36:05] Speaker 3: in arrays in JavaScript, so of course reduce the same name.
[36:08] Speaker 3: So it's great, and they do different things. It's great.
[36:10] Speaker 1: We'll be confusing at all, not at all, no.
[36:12] Speaker 3: Not at all, but no, those are just ways to
[36:16] Speaker 3: chain in ox in our XGS in order to do
[36:24] Speaker 3: things with the data once you subscribe, you know, once
[36:26] Speaker 3: you're doing something with your observable, right, So map would
[36:29] Speaker 3: allow you to just transform the data and return switch
[36:34] Speaker 3: map allows you to call another observable or promise and
[36:36] Speaker 3: then return that. It's just with various ways of chaining.
[36:40] Speaker 3: And there's I don't know how many, there's at least
[36:44] Speaker 3: twenty or so, if not more. Various ones won't bore
[36:48] Speaker 3: you with the details, really, people can read the dogs.
[36:52] Speaker 1: But yeah, yeah, no, I think the main thing to
[36:54] Speaker 1: know is there's a way to do this. Just go
[36:57] Speaker 1: look at the docks. Yeah, very good. Any other gotchas
[37:04] Speaker 1: that people find when they're starting the ACENC got down
[37:08] Speaker 1: the ACENC path.
[37:09] Speaker 3: I'd say where to put your catches, like where where,
[37:13] Speaker 3: and how to catch your errors, like because you can
[37:17] Speaker 3: say await my promise, dot catch and then return a
[37:21] Speaker 3: different value if it fails in a series of your
[37:24] Speaker 3: asinka weights and then still put it in a try
[37:26] Speaker 3: catch block, which so means that if anything else in
[37:29] Speaker 3: your function fails, then it would just go ahead and catch.
[37:31] Speaker 3: So I would say, think through where your catches are
[37:34] Speaker 3: and what they affect, so that you can know how
[37:37] Speaker 3: and where you're handling your errors, because you can't actually
[37:41] Speaker 3: do put a dot catch something dot catch inside of
[37:44] Speaker 3: a try catch block and then figure out where your
[37:46] Speaker 3: is being caught and by what and how right and
[37:49] Speaker 3: the fact that a trycatch block the catch doesn't return
[37:53] Speaker 3: a value. However, a dot if you do my promise
[37:57] Speaker 3: doc you know, fetch my url whatever, dot catch, so
[38:00] Speaker 3: my promise dot catch, you can actually take the air
[38:04] Speaker 3: or swallow the air and return it if a value
[38:06] Speaker 3: should at sale. So you could potentially have something where
[38:09] Speaker 3: if you can't get a value, you're going to return
[38:11] Speaker 3: some defult object. Right, you could totally do that or no, yeah,
[38:17] Speaker 3: but then what do you do with that air? Or
[38:18] Speaker 3: do you just swallow it and never know what happened?
[38:21] Speaker 3: Do you send it somewhere for air handling? What do
[38:23] Speaker 3: you like if you're going to swallow it, what are
[38:26] Speaker 3: you going to how do you want to handle that
[38:28] Speaker 3: in terms of you knowing it happened or do you
[38:30] Speaker 3: even care?
[38:31] Speaker 1: Right? So it's like, as long as something got returned, right, if.
[38:35] Speaker 3: My dude entered his wrong password, I don't really care
[38:39] Speaker 3: to send that to my server.
[38:40] Speaker 1: You know, right, Like yeah, and c sharp reez that
[38:44] Speaker 1: catch handlers for logging primarily and transforming whatever data is
[38:49] Speaker 1: going to be returned if it's in a method. Right,
[38:51] Speaker 1: If you have a method, you put the whole thing
[38:54] Speaker 1: in a try, but you put the return value up
[38:56] Speaker 1: the top before the try, and then modify it if
[39:00] Speaker 1: everything is fine and it's not all I fits if
[39:03] Speaker 1: you get an exception and return it at the bottom
[39:05] Speaker 1: no matter what, or in a finally. But you know,
[39:08] Speaker 1: that's just a pattern that I use a lot. I've
[39:11] Speaker 1: seen it abused. I've seen try catches nested within catches
[39:17] Speaker 1: for example.
[39:18] Speaker 3: Yep, I've seen those two not good. I've seen those
[39:22] Speaker 3: good or.
[39:22] Speaker 1: Hidden dependencies where every time you tested it, it loaded in
[39:25] Speaker 1: a particular order, so you never realize that actually it
[39:28] Speaker 1: had an order dependency that you weren't protecting yourself from.
[39:30] Speaker 1: Oh no, yeah, it's terrible. Yeah.
[39:32] Speaker 3: Race conditions are fun too, when you've forgotten away somewhere,
[39:35] Speaker 3: oh right, or.
[39:36] Speaker 1: You forgot yeah, oh yeah, that's right.
[39:39] Speaker 3: We do have finally as well. On javascripts we do
[39:42] Speaker 3: have finally as well. But finally in an observable one,
[39:44] Speaker 3: finally and I promise don't work the same, because of
[39:46] Speaker 3: course they don't. Course not, what do you want they
[39:51] Speaker 3: do when they they do when they don't. So finally
[39:54] Speaker 3: in a promise does exactly what you think it's going
[39:57] Speaker 3: to trigger, whether you've succeeded or failed.
[40:00] Speaker 1: Right.
[40:00] Speaker 3: Finally, in a stream will only hit when the stream completes,
[40:04] Speaker 3: so it's not after every successful value. Once the stream completes,
[40:09] Speaker 3: that means you've closed off, or you've said dot complete
[40:13] Speaker 3: or you've shut that down. Well that's once the stream complete. So,
[40:18] Speaker 3: but it's worth noting the difference that it's not going
[40:20] Speaker 3: to be every time you get a value.
[40:22] Speaker 2: Right, this is back to that stream versus one and
[40:24] Speaker 2: done mindset right, correct, It actually is the same. It
[40:29] Speaker 2: is actually I responded the same event it's the closing
[40:32] Speaker 2: of the socket that raises the event. It's just that
[40:35] Speaker 2: in an observable, it doesn't close to you complete exactly.
[40:38] Speaker 1: Can I just make an observation? What's really amazing to me?
[40:41] Speaker 1: We've been doing this show for how in years? Twenty
[40:46] Speaker 1: three something like that, all right, and you've been there
[40:49] Speaker 1: for most of them, Richard, So don't say you're the
[40:51] Speaker 1: new kid. But when I started it, I said, we
[40:55] Speaker 1: are never going to read code on this show, right, right,
[41:00] Speaker 1: But we're getting very close with this. We are well,
[41:05] Speaker 1: and I think we've been close before. I'm following it,
[41:08] Speaker 1: and I'm thinking that a lot of people are following
[41:11] Speaker 1: it too. Yeah, I know.
[41:12] Speaker 2: I appreciate that. I've never had this clearer in my
[41:14] Speaker 2: head than right now.
[41:16] Speaker 1: Yeah, right that. This is why I wanted to call
[41:17] Speaker 1: Martine in the first place. It's like, oh good, if
[41:20] Speaker 1: she's explaining it, I'll probably understand it.
[41:23] Speaker 2: So yes, now, now you see all the roles for
[41:25] Speaker 2: each of these pieces, So that's good. It just makes
[41:29] Speaker 2: sense to where and why you would use this but
[41:32] Speaker 2: don't use it everywhere all the time. Why is that
[41:35] Speaker 2: just complex?
[41:35] Speaker 3: Well, I don't know. You know, if you have a
[41:39] Speaker 3: hammer might as well.
[41:40] Speaker 1: No, here's a hammer.
[41:43] Speaker 3: Yeah, I can CSS important everything. It'll be fine.
[41:47] Speaker 1: No, I can't believe you said that. That's something i'd say.
[41:54] Speaker 3: I have to make fun of it. I have to
[41:56] Speaker 3: make fun of my own world a little bit.
[41:58] Speaker 2: Sure, I appreciate that, and we all do that, but
[42:02] Speaker 2: I do feel like it introduces complexity, and it's only
[42:05] Speaker 2: if you need it you should be asynchronous. That this
[42:08] Speaker 2: does delay the rendering of a page. This isn't essential
[42:11] Speaker 2: for people being able to do their work. Oh yeah,
[42:14] Speaker 2: I really like a web page.
[42:16] Speaker 1: I've that's crafted in a way where I'm still able
[42:19] Speaker 1: to click on what I need because I knew where
[42:21] Speaker 1: it was before the page was even finished loading. And
[42:23] Speaker 1: it'll continue. It's fine. And an ACYNC tolerates that.
[42:26] Speaker 3: Yeah, And that actually has more to do with how
[42:29] Speaker 3: the JavaScript is loaded into the I mean there's two
[42:33] Speaker 3: aspects to that. There's one, how are you loading that
[42:35] Speaker 3: JavaScript while into the browser? Right, because you you might
[42:39] Speaker 3: have browser you might have JavaScript that's needed immediately on
[42:42] Speaker 3: the page load, versus you can get there when it
[42:45] Speaker 3: gets there and then you can the actual the If
[42:49] Speaker 3: you're doing dumb HTML, you've got the source on the
[42:53] Speaker 3: source attribute. You can go ahead and put an acinc
[42:55] Speaker 3: decorator and go ahead and make that, I think. But
[43:00] Speaker 3: so that's part number one, and then part number two
[43:03] Speaker 3: is how did you structure your HTML and what not
[43:06] Speaker 3: to render based on when? When things load right? And
[43:10] Speaker 3: what data do you need to load? Wet But there's
[43:12] Speaker 3: two there's two aspects to that, which is also how
[43:15] Speaker 3: is this JavaScript itself being loaded into the browser that
[43:18] Speaker 3: may or may not block the rendering of the browser.
[43:21] Speaker 3: And now you're getting into the whole core web vitals
[43:23] Speaker 3: thing and all that fun stuff.
[43:24] Speaker 1: But yeah, just because I'm too impatient away for a
[43:27] Speaker 1: whole patient render. You know, a lot of these rules
[43:30] Speaker 1: that Martine is talking about also apply in Blazer programming. Yeah,
[43:33] Speaker 1: I mean it's basically web programming, you know, in web
[43:37] Speaker 1: is web. So that's a good if any of the
[43:39] Speaker 1: Blazer programmers listening too. It's a good rule to only
[43:42] Speaker 1: use a sink when you need a sinc. Very good rule. Yeah,
[43:45] Speaker 1: your environment's still the same, it's just the coding language chain,
[43:48] Speaker 1: that's right, because it presumably the user's needs are the same,
[43:52] Speaker 1: like users.
[43:53] Speaker 3: Are impatient presumably Yeah, yeah, yeah, one the faster you
[43:58] Speaker 3: get it up there too. I mean there's from a
[44:00] Speaker 3: pure marketing and se O. Your SEU has good. If
[44:04] Speaker 3: you've got a quicker to click time, your SEO is
[44:06] Speaker 3: going to go up. Your marketing people are going to
[44:08] Speaker 3: be happier, Like, there's all the reasons right right.
[44:11] Speaker 1: People are never happy happy? Did I say that out loud?
[44:14] Speaker 1: I feel bad. You want some fun when you're working
[44:19] Speaker 1: in a development shop, go talk to the sales guys.
[44:22] Speaker 1: Oh yeah, oh yeah, they don't like us. You know,
[44:25] Speaker 1: they do not like us in the end, and we
[44:27] Speaker 1: don't like them because they promise features you know that
[44:31] Speaker 1: you don't even know about. You don't even know about
[44:33] Speaker 1: much less know when you're delivered. Good idea to have
[44:35] Speaker 1: lunch with a sales guy once a week. What have
[44:37] Speaker 1: you promised this year? A good idea for the manager?
[44:41] Speaker 3: Where did you get your estimates?
[44:43] Speaker 1: Yeah? What lines have you told?
[44:45] Speaker 5: Oh?
[44:45] Speaker 3: You just rolled a handful of dies?
[44:47] Speaker 1: Got it? I remember working for a software company and
[44:53] Speaker 1: he basically used the word on all the time as
[44:59] Speaker 1: a verb. Something of part of his job description was
[45:02] Speaker 1: constantly unaff ing the things that need that were screwed up.
[45:07] Speaker 1: He was an angry man.
[45:11] Speaker 3: I've never used I've never used the F word in relationships,
[45:17] Speaker 3: my job, or anything I was doing.
[45:19] Speaker 1: Never, no, no, never never never. Okay, you heard it
[45:25] Speaker 1: here first, folks. It's actually not a bad job title,
[45:29] Speaker 1: you know, Carl Franklin. It's like, oh, you're the as man.
[45:40] Speaker 3: We had a q I person we called the Harborder
[45:43] Speaker 3: of Doom for a long time.
[45:44] Speaker 1: I like that the Arbor of Doom approaches.
[45:50] Speaker 3: In terms of fun titles.
[45:54] Speaker 1: Yeah, definitely.
[45:55] Speaker 2: When I was in my INFOSEC roles, it was like, oh,
[45:58] Speaker 2: here comes the business impediment off.
[46:06] Speaker 3: Now which role was that? Because I can think of
[46:08] Speaker 3: multiple roles for that.
[46:09] Speaker 1: Yeah. Yeah, there's a bunch of folks like that. You
[46:12] Speaker 1: could argue the QA guys that, but INFOSEC especially, Yeah. Yeah,
[46:18] Speaker 1: you will authenticate this person before anything proceeds. Sellers to that.
[46:23] Speaker 1: You know what though, I mean, you know, if you
[46:24] Speaker 1: have special roles in your database for users that they're
[46:28] Speaker 1: never going to see what they are, you can make
[46:29] Speaker 1: them whatever you want, right, So get creative. Some day
[46:36] Speaker 1: that person realizes you tag their role as Harborder of Doom.
[46:41] Speaker 1: Some day Harboringer of Doom.
[46:49] Speaker 4: I did have a client once. One of the first
[46:51] Speaker 4: things I had to do for them is they asked me.
[46:52] Speaker 4: They're like, okay, we've been laxed, but unfortunately now we're
[46:56] Speaker 4: shipping you know, this bundle to our clients, and so
[46:59] Speaker 4: they can see our code. You need to go through
[47:02] Speaker 4: and find all the profanity and.
[47:04] Speaker 1: Remove and also just like comments like wtf what was
[47:12] Speaker 1: I thinking? My family clearly wrote this because nobody else
[47:16] Speaker 1: could have No.
[47:18] Speaker 3: My favorite was the number of times I all because
[47:20] Speaker 3: I E. And I've written this in code basiness before.
[47:23] Speaker 3: So it made me double laugh because I was like,
[47:25] Speaker 3: I haven't touched this before. How is my comments in here?
[47:28] Speaker 3: Because I E. Is being a little sleep.
[47:33] Speaker 1: Yes, that's legit. They shouldn't even be removed. That's just
[47:37] Speaker 1: being honest, right right, I E. I E. Defect resistance requirements. Yep,
[47:47] Speaker 1: Like wtf I see that in code all the time?
[47:51] Speaker 1: Who wrote this crap? Well?
[47:56] Speaker 2: I had a standard tag, you know, like a paragraph
[47:58] Speaker 2: at the top of each of the perform misdoing things.
[48:00] Speaker 2: Just like if this doesn't make sense to you, do
[48:02] Speaker 2: not touch it. Yeah, ask someone else.
[48:06] Speaker 3: Yeah, yeah, I do have a I do have a
[48:09] Speaker 3: phone on a project. If you think about touching this file,
[48:13] Speaker 3: I will haunt you.
[48:15] Speaker 1: Yeah. The curse the curse, curse on your head comes
[48:19] Speaker 1: your Liam Neeson. I will find you and I will
[48:22] Speaker 1: kill you.
[48:25] Speaker 3: Yes.
[48:27] Speaker 1: Oh what the heck? Were we talking about JavaScript?
[48:30] Speaker 3: Of JavaScript and where we love it?
[48:32] Speaker 1: Yeah, the wonders. That's why we got to profanity. It
[48:35] Speaker 1: was inevitable. I mean, oh man, oh man. Well I'm
[48:42] Speaker 1: really grateful. This is a great explanation. It seems it
[48:46] Speaker 1: seems like you shouldn't be afraid of this stuff. It's
[48:48] Speaker 1: been and it's been true for a few years now.
[48:50] Speaker 1: Like I just double checked, and like since roughly twenty
[48:53] Speaker 1: twenty one, every browser responded more or less the same
[48:56] Speaker 1: to this, so you can count on it.
[48:59] Speaker 3: That's good and available in Node as well, so if
[49:01] Speaker 3: you're in you know, if you're in that side of
[49:03] Speaker 3: the universe, it does totally work there too, which is
[49:07] Speaker 3: super cool.
[49:07] Speaker 2: If you weren't frustrated enough with no JS, try ASNC
[49:10] Speaker 2: and no j as.
[49:11] Speaker 1: Yeah.
[49:13] Speaker 3: Well that's the thing though for a node for a
[49:15] Speaker 3: long time you had to have a package for doing
[49:17] Speaker 3: a sync and so now it's actually legitimately available in node.
[49:23] Speaker 1: They're using the engine. Yeah, because it's part of the language.
[49:26] Speaker 1: Yeah right, yeah, that's good. Uh well, Martine Is there
[49:30] Speaker 1: anything that we missed that you want to anything? You
[49:32] Speaker 1: want to plug or talk about your book? You said
[49:35] Speaker 1: you wrote a paper.
[49:36] Speaker 3: Oh, I'm I mean I have my blog articles up
[49:40] Speaker 3: on the blog for Andromeda Galactic dot com. I also twitch.
[49:46] Speaker 3: I'm working on moving my Twitch to Monday nights. So
[49:50] Speaker 3: definitely come look food, look for me there. Don't hesitate
[49:55] Speaker 3: to come say hi. It's kind of hip random what
[49:58] Speaker 3: will hit but it'll be front and dev something and you.
[50:01] Speaker 1: Have Martine dot dev. Can you code and chat at
[50:04] Speaker 1: the same time like that? I can't really challenge that's crazy.
[50:08] Speaker 3: As long as it's something like there's so much in
[50:11] Speaker 3: UI that's memorization, that's the same stuff no matter what.
[50:16] Speaker 3: Like yeah, I might do my column with's through my robe.
[50:20] Speaker 3: Height's a little bit different depending on the layout. But realistically,
[50:23] Speaker 3: writing a writing the CSS to write a great is
[50:25] Speaker 3: going to be more or less the same every time,
[50:27] Speaker 3: or a flex or whatever. Yeah, as long as I
[50:29] Speaker 3: figured out what I'm going to write most of the
[50:32] Speaker 3: actual typing it out, I can do well. Chatting nice,
[50:36] Speaker 3: not too difficultly.
[50:37] Speaker 1: And your your personal website is Martin dot dev right correct?
[50:41] Speaker 3: Yes, And all the links are all there.
[50:44] Speaker 1: Yeah, stream links there, the blog links there, like everything
[50:47] Speaker 1: you need is there. You told us the story, but
[50:48] Speaker 1: tell the users how you got that.
[50:50] Speaker 3: So when the dot dev extension came out for being
[50:54] Speaker 3: able to get domains, the first thing I did, and
[50:56] Speaker 3: like right came out. I want to look, I wanted
[50:58] Speaker 3: to get Martin dot dev and it was Bob, and
[51:01] Speaker 3: I cussed up because I never used the F word,
[51:08] Speaker 3: so it was definitely not used in this use case.
[51:11] Speaker 3: Cursing of whoever might have bought it, et cetera, et cetera,
[51:14] Speaker 3: et cetera. It turned out that my partner Michael had
[51:18] Speaker 3: bought it for me, so so nice.
[51:21] Speaker 2: A story from rage to delight exactly.
[51:26] Speaker 1: I mean, that's that's like if I had Carl dot com.
[51:29] Speaker 1: You know, that's really good Martin dot dev fantastic, really good.
[51:33] Speaker 3: Yeah well, I mean it has the advantage of not
[51:34] Speaker 3: being too common of a name, so got lucky.
[51:37] Speaker 1: I'm not well, this has been great, Thank you very much, Martine.
[51:40] Speaker 1: And uh, well we'll talk to you probably in a
[51:43] Speaker 1: year or so, because we seem to be talking to
[51:44] Speaker 1: you once a year. Yeah.
[51:47] Speaker 3: Yeah, well, I'll be delighted to come back anytime you
[51:51] Speaker 3: want me.
[51:52] Speaker 1: Great, Thanks all right, and we'll talk to you next
[51:54] Speaker 1: time on dot net rocks. Dot net rocks is brought
[52:18] Speaker 1: to you by Franklin's Net and produced by Pop Studios,
[52:22] Speaker 1: a full service audio, video and post production facility located
[52:26] Speaker 1: physically in New London, Connecticut, and of course in the
[52:29] Speaker 1: cloud online at pwop dot com.
[52:33] Speaker 5: Visit our website at d O T N E t
[52:36] Speaker 5: R O c k S dot com for RSS feeds, downloads,
[52:40] Speaker 5: mobile apps, comments, and access to the full archives going
[52:44] Speaker 5: back to show number one, recorded.
[52:46] Speaker 1: In September two thousand and two. And make sure you
[52:49] Speaker 1: check out our sponsors. They keep us in business. Now,
[52:52] Speaker 1: go write some code, see you next time.
[52:55] Speaker 5: You got you
[53:00] Speaker 3: D that Bess home and my taxes a line d

Shows are listed from Apple Podcasts' charts and directory, and Podcast Index where it is used. Every show and episode belongs to its publisher and plays from the publisher's own feed; this site hosts none of them.
