I actually use JavaScript generator functions

preview_player
Показать описание

JavaScript generator functions have been around for a long time, but you rarely ever see them actually used. I actually do use them for day-to-day work and in this video I'll explain what they are and why I'm using them.

MY GEAR:

0:00 JavaScript Generator Functions
0:20 Iterators and Iterables
1:06 Generator Function Example
1:35 Where I use generators
2:37 How it works

#javascript

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

I use generators to chunkize humongous amounts of data and process them asynchronously without gaping the render performance

figloalds
Автор

Generators are amazing for running some form of "get source data" in data transformations. it keeps the memory usage "low" while still being able to processed with a foreach on the full dataset, essentially batching a huge dataset

thirdbeat
Автор

I use generators when working with files when I don’t necessarily want/need to keep the entire file in memory at once. I wrote a custom pcap library for working with network dumps for example, and use generators to iterate over the packets in the pcap dumps

jondbarrow
Автор

I don't really see the benefit and it looks like it'd be a pain to debug

ups_
Автор

I actually used a generator function... once, in my 6 years of using JS.

jokerx
Автор

Generators were outshadowed by async/await since you can do almost all of generator's stuff by them.

janplys
Автор

Ok, but why? It doesn't sound like something that we couldn't do with just normal code. And it would be KISS complaint, because generators seem like completely over engineered solution. But maybe it is just me and I'm just not familiar with it. Idk.

anj
Автор

I've used generators mostly for stream processing. Proxies are another ES2015 feature that I use a lot that is not widespread.

theobrominator
Автор

So if I'm understanding correctly, what your code is doing is basically `yield`ing interpolated values based on time passed? That's kind of interesting, definitely out-of-the-box thinking. Personally I'd have something that I can request a value from, but essentially that's what you're doing when you call `.next()` on the generator. I haven't considered the idea of using a generator to yield values based on time passed, that's definitely interesting. As for actual-use of generators, I used one recently: I'm wrapping an API that takes a page number and returns a batch of values, and exposing it as a generator that will yield each row in the returned data, and automatically request the next page from the API as needed.

pfqniet
Автор

I think you rarely ever see generators used because they are an overly-complicated solution for most problems.

dokkenrox
Автор

effect uses generators heavily. Amazing use of obscure feature

danielmontilla
Автор

Make the text smaller please, my ants can't read it

yadusolparterre
Автор

so, use generator to model state machines

ThanhNguyen-slkd
Автор

Didn't know this existed. Looks awesome. Definitely feels like some kinda homebrew utility.

blossomcherrypink
Автор

first time seen this. the only way i think i will use it is to have more control in recursivity or in the example you use.

cases that i do not normally have XD

zero
Автор

Since I discovered effect ts I never use async await again and use generators instead

AndresJimenezS
Автор

Worked at a company that used KoaJS (for some dumb fuckin reason), the controllers were generator functions

RaniLink
Автор

Generator is one of underrated feature in js.
I'm actually use plenty of times where it's the best optimize way to do things.

alexjim
Автор

I remember working for a company where there entire Node backend was comprised of generator functions.

They basically created an entire framework with them on top of Moleculer.

bigk
Автор

i gonna be honest with you, it"s jusy my personal opinion, i stopped watching your videos because you make angular look so complicated, i work like a full stack developer with rails, react or angular, and your videos sometimes are weird, i don't know if you make it to be more clever or what it's the real benefit

haroldpepete
welcome to shbcf.ru