i using graphicsmagick node. crop photos , retrieve exif data of photos uploaded user. don't want block flow of request waiting these task completed, therefore need use asynchronous functions able so. , think should able these i/o operations node.js makes async itself.
but see functions in graphicsmagick node synchronous functions. not being able sure how achieve looking for.
one idea comes mind write function callback , have graphicsmagick processing done inside it. , use .nexttick() function achieve asynchronous flow. not totally sure if fine. , there asynchronous functions graphicsmagick.
please me , example code appreciated how asynchronous functions graphicsmagick.
update:
actual answer @saransh mohapatra wrong. after little investigation turned out methods perform operations on images, not perform append arguments list used after when write or call buffer related methods executed in order get/write actual image buffer.
here details on in example of blur:
- we call
blur: https://github.com/aheckmann/gm/blob/master/lib/args.js#l780 - it calls
this.outcall: https://github.com/aheckmann/gm/blob/master/lib/command.js#l49 - which has method made when constructed: https://github.com/aheckmann/gm/blob/master/lib/command.js#l34
- which -
a.push(arguments[i]);, concats list (to other arguments). - thats it.
then when write called:
- https://github.com/aheckmann/gm/blob/master/lib/command.js#l62
- it gets list of arguments
self.args(): https://github.com/aheckmann/gm/blob/master/lib/command.js#l78 - which filters off reserved fields: https://github.com/aheckmann/gm/blob/master/lib/command.js#l274
- so arguments joined in
_spawncalledwrite: https://github.com/aheckmann/gm/blob/master/lib/command.js#l187 - thats it.
so based on this, method makes operations on image, not save or persist buffer of - not need async, not work @ all. means - need worry them.
old:
best approach heavy processing stuff use separate processes.
can create small node.js process, have communication abilities main process (zeromq choice here).
this separate process have notified file (path) , it, can send data main process makes such decisions via zeromq.
this approach allow have independence in way main (web?) node processes work, possibility in future scale separate hardware/instances.
practice (unix-like application logic separation).
Comments
Post a Comment