JavaScript’s Deferred Promise Pattern

preview_player
Показать описание
The deferred pattern is a great way to add new flexibility to the way you use promises.

*My Links*
Рекомендации по теме
Комментарии
Автор

If you’ve used the deferred pattern before, share your use case in a comment!

andrew-burgess
Автор

my initial thought was "what that's stupid" but through the example I thought "yeah that can be useful". this was because the way it originally seemed was that you returned the deferred object itself, and the caller of the function got back the promise as well as a way to resolve and a way to reject, but since you just return the promise it's just a more compact way to do it than you would with a promise

samuelgunter
Автор

I'm most a backend dev, but this is super handy even for certain asynchronous operations *I* would do. Love it!

kalelsoffspring
Автор

it'd be super cool to see more about what you're up to with the audio APIs!

dimitrimitropoulos
Автор

Thank you so much for helping beginners advance their level of JS knowledge. Your top-level tutorials are always presented so clearly and concisely that even I can benefit.

kerrykreiter
Автор

Super useful pattern for mocked promises in tests. Gives test full control of promise resolution or rejection

dennisk
Автор

Wow thank you, I wish you post more advanced content like this.

oscardasilva
Автор

Would love seeming more patterns videos like this!

hideinbush
Автор

Hi @Andrew. This was a great topic and you did teach us well, but if you give us more use case for this, it would be better.

tempaccount
Автор

This is really cool. Please more patterns!!

deamorta
Автор

I think that pattern makes your code way less readable when you could just say

const asyncBlob = new Promise(resolve => ...)

and wrap it around the media recorder stop event listener and then return asyncBlob in the returned function. I think using a plain promise here creates a more distinct point of definition for how the value of the blob gets resolved and what logic is required to resolve it.

This just feels like abstraction for the purpose of abstraction.

EthanStandel
Автор

Great video. I've never seen this pattern before. Thank you for sharing!

thi-m
Автор

This is super cool. Will be looking for ways to use it going forward!

magicbob
Автор

this is great, I used to to create a chainable promise returning Api call!

bahmanasheghi
Автор

It's unusual for me to a actually use the code from a video including the most interesting and I have been learning a lot from many but it is the second time I am using the code from your video to play with it and such

Luxcium
Автор

I must say I never really cared about TypeScript that much, but the way you explain TypeScript and the possibilities / ease of use is making me interested.

darealmexury
Автор

There is a simple enough way to do this without this pattern, just wrap setting up the event handlers inside the promise, bind it to a variable, then start, and return your function returning the promise. Not to say this pattern isn't useful, but in my experience it's very occasionally useful for very convoluted async control flows.

lierdakil
Автор

Yeah deferred rocks, it essentially encapsulates in a reusable way whenever I've done new Promise(.. and captures the resolve function by binding it to an outer variable. Deferred is way less to reason about.

seannewell
Автор

Love this pattern! I’m using something very similar with the spawn child API to capture the exit event. I need to know the return code, and that’s only available on exit callback.

helsontaveras
Автор

I don't get it, where did you get that "Deferred" type from?

grerff
join shbcf.ru