ruby - Does it make sense to include callback and errback when running inside an EM.defer? -


i'm trying integrate blocking libraries/operations inside eventmachine, , i've considered encapsulating such code inside class includes em::deferrable. make sense have such code in deferrable object:

class whatever   include em::deferrable   def some_operation     result = some_blocking_operations     if result.considered_success?       succeed(result)     else       fail(result)     end   end end 

or should stick to:

op = lambda   result = some_blocking_operations end  cb = lambda |res|   # kind of if here check if it's success or failure end  em.defer(op,cb) 

personally, prefer first one, since me reads bit better. make sense implement deferrable in such case?

your first implementation looks way more oop me. using lambdas great , flexible if things start complicated you'll endup bunch of random lambdas , no way tell doing.

to answer question, yes makes sense me create class run blocking code.

also, you'll have place put private methods related blocking actions logic.

finaly, if name class carefuly, won't hard developer understand basic idea behind class. if further informations needed, have digg code.

i think lambdas poor design in case. pretty sure you'll thanking using classes when things more complexe (it does).


Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -