[Backgroundrb-devel] Defer multiple methods within the same worker to the thread pool?

Ryan Leavengood leavengood at gmail.com
Sun Feb 3 00:02:44 EST 2008


On Feb 2, 2008 11:56 PM, Benjamin H. Bryant <iambenbryant at gmail.com> wrote:
> Within a threaded worker, I would like to have multiple methods.  Will
> the following code work?
>
> def method_1(args)
>
>    thread_pool.defer(args) do |args|
>      #work
>    end
>
> end
>
> def method_2(args)
>
>    thread_pool.defer(args) do |args|
>     #work
>    end
>
> end

Yes that will work fine. The thread_pool.defer call just packages the
block and arguments into a class which is put into a queue. The
thread_pool pulls from that queue and executes the packaged code in
the order it was received.

Since I was making use of thread_pool.defer myself I read the source
to see what it was doing, which is nothing too crazy.

Regards,
Ryan


More information about the Backgroundrb-devel mailing list