Skip to content

Provides ability to run more callbacked methods backed by EventMachine of single or more objects by elegant, readable and transparent way in a linear sequence, so subsequently in single batch.

License

martinpoljak/em-batch

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

EventMachine Batch

em-batch provides ability to run more callbacked methods of single or more objects by elegant, readable and transparent way in a linear sequence, so subsequently in single batch.

Two classes are available, sequencer and more general batch. Batch supports more objects in one batch, sequencer is syntactic sugar in fact for single object.

It's implementation of the callback-batch gem, but customized for running in EventMachine environment, so calls will be fully multiplexed to more subsequent ticks.

See some trivial examples:

require "eventmachine"
require "callback-batch"

class Foo
    def foo1
        yield :foo1
    end
    def foo2
        yield :foo2
    end
end

class Bar
    def bar1
        yield :bar1
    end
    def bar2
        yield :bar2
    end
end


EM::run do

    ### Sequencer

    s = CallbackSequencer::new(Foo::new)
    s.foo1
    s.foo2

    s.execute do      # now will be both methods executed
        p s.results   # will contain [:foo1, :foo2]
    end

    ### Batch

    s = CallbackBatch::new
    f = Foo::new
    b = Bar::new

    s.take(f).foo1
    s.take(b).bar2

    s.execute do      # now will be both methods executed
        p s.results   # will contain [:foo1, :bar2]
    end

end

Copyright

Copyright © 2011 – 2015 Martin Poljak. See LICENSE.txt for further details.

About

Provides ability to run more callbacked methods backed by EventMachine of single or more objects by elegant, readable and transparent way in a linear sequence, so subsequently in single batch.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages