EyalAr / lwip

Light Weight Image Processor for NodeJS
MIT License
2.37k stars 230 forks source link

work synchronously #238

Closed digitalica closed 8 years ago

digitalica commented 8 years ago

Would it be possible to work synchronously? I tried to use lwip to process a dir tree with images and other files, no need for async operation.

Using deasync didnt work unfortunately (see issue 49 there)

nvartolomei commented 8 years ago

@digitalica why would you want to make it work sync? Isn't async actually one of the main nodejs and ecosystem strength?

If you want to make your code a little bit more readable you could try caolan/async. In particular async.(each|forEachOf|map) and async.series.

digitalica commented 8 years ago

@nvartolomei Yes, async is the ecosystem strength, and I like it in many places. But here i'm trying to do batch conversion on a dir tree containing hundreds of files, images and others, that are in part related and dependant on each other. Syncronous code is much more easy to read (at least for me) and debug there. Although it probably could be done async too...

I do use async (already in other places, but now here too) but succeed in working (more) synchronously using Fibers. So my batch conversion is working now using lwip!

Still, I think it would be nice if lwip could work synchronous too. (Just like fs)

felixfbecker commented 8 years ago

@digitalica Use Bluebird's Promise.promisifyAll together with Promise.coroutine and you can write async code like sync code ;)

EyalAr commented 8 years ago

@digitalica lwip is async by design. As you and others mentioned, there are good abstractions to handle async code (caolan/async, promises, etc.).