How to execute same code for callback and errback?

21 views
Skip to first unread message

Christoph Pilka

unread,
May 18, 2012, 11:09:14 AM5/18/12
to EventMachine
In one of my cases I have to execute exactly the same code within
callback as well as in errback. How would you avoid DRY in such
situation?

Iñaki Baz Castillo

unread,
May 18, 2012, 2:22:33 PM5/18/12
to eventm...@googlegroups.com
2012/5/18 Christoph Pilka <c.p...@asconix.com>:
> In one of my cases I have to execute exactly the same code within
> callback as well as in errback. How would you avoid DRY in such
> situation?

Some EM methods allows both a Proc instance of a block. In the former
case you can do:

my_proc = Proc.new do |param|
# do something with param
end

em_object.callback(my_proc)
em_object.errback(my_proc)

--
Iñaki Baz Castillo
<i...@aliax.net>

Paul Makepeace

unread,
May 18, 2012, 2:32:38 PM5/18/12
to eventm...@googlegroups.com
Check out "deferrable gratification", a grab-bag of goodies to make EM
life a little easier. Specifically,

https://github.com/samstokes/deferrable_gratification#bothback-when-you-absolutely-positively-got-to

Paul
> --
> You received this message because you are subscribed to the Google Groups "EventMachine" group.
> To post to this group, send email to eventm...@googlegroups.com.
> To unsubscribe from this group, send email to eventmachine...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/eventmachine?hl=en.
>

Christoph Pilka

unread,
May 18, 2012, 3:02:17 PM5/18/12
to EventMachine
OK, thanks guys for the hints ...

Paul Makepeace

unread,
May 22, 2012, 9:17:33 PM5/22/12
to eventm...@googlegroups.com
(ITYM:
em_object.callback(&my_proc)
em_object.errback(&my_proc)
 

Paul)
Reply all
Reply to author
Forward
0 new messages