DEV Community

Discussion on: Using JavaScript Promises for Non-Async Control Flow?

Collapse
nickytonline profile image
Nick Taylor (he/him) • Edited

As they mention, it is for async / deferred operations so not a good use case for synchronous operations. Good news though, the pipeline operator was proposed and is moving along quite well. If you want to read about it, @kayis has an article that talks about it.

In the meantime while we wait for the pipeline operator, you could compose your functions. If you're new to composition, @kyleshevlin offers a short but very clear and informative explanation in his egghead.io video, Build Complex Functions with Function Composition in JavaScript.

Collapse
dmerand profile image
Donald Merand Author

That's good news that JS is getting a pipeline operator! I'm occasional enough with my JS coding that I prefer to skip using build environments like Babel if I can, but it'll be awesome when that feature gets wider browser support.

I haven't watched the video, but in DuckDuckGo'ing JS composition of course it makes sense - you just manually curry your functions. I've been spoiled by languages that do that for me :)

I still like the part where promises let me pass errors through + deal with them at the end... I wonder about a good composable way to do that...

Collapse
nickytonline profile image
Nick Taylor (he/him) • Edited

I haven't done much RxJS, but that's probably a good use case for piping. See RxJS 5.5, piping all the things.