On Nov 18, 2:49 pm, "Aman Gupta" <[EMAIL PROTECTED]> wrote:
> > In Eventmachine you would use EM::Deferrable for all of your Sequel
> > calls. EM would handle spawning any ruby threads (green threads in
> > MRI, native threads in JRuby). Then use #set_deferred_status in the
> > Deferrable to notify your business logic when the Sequel calls have
> > completed.
>
> You're confusing EM.defer with EM::Deferrable. EM::Deferrable has
> nothing to do with threads, it simply stores a list of callbacks to
> invoke when a certain state is reached. EM.defer uses a ruby
> threadpool of 20 threads and provides a second callback to receive
> notifications when code running in the thread has executed.
>
> The approach I use in my projects it to combine Sequel's SQL
> generation with the em-mysql async api:
>
> EventedMysql.select( User.where(:age > 10).limit(10).sql ) do |rows|
> rows.each do |data|
> user = User.load(data)
> p user.age
> end
> end
You may be able to make this even nicer:
class Sequel::MySQL::Dataset
def execute(sql)
EventedMysql.select(sql){|r| yield r}
end
end
User.where(:age > 10).limit(10).each{|user| p user.age}
Not sure if that would work or not, but it would make the code a lot
nicer. You'll obviously need to handle deletes, inserts and updates
differently, you can override execute_dui or another method for those.
Jeremy
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"sequel-talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/sequel-talk?hl=en
-~----------~----~----~----~------~----~------~--~---