Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: igrigorik/em-synchrony
base: 8795b83221
...
head fork: igrigorik/em-synchrony
compare: 6f23d79b94
  • 2 commits
  • 3 files changed
  • 0 commit comments
  • 2 contributors
Commits on Sep 03, 2012
@kostya kostya # add em-defer ab78cb2
Commits on Sep 05, 2012
@igrigorik Merge pull request #133 from kostya/master
add em.defer
6f23d79
Showing with 49 additions and 1 deletion.
  1. +1 −1  README.md
  2. +8 −0 lib/em-synchrony.rb
  3. +40 −0 spec/defer_spec.rb
View
2  README.md
@@ -8,7 +8,7 @@ Collection of convenience classes and primitives to help untangle evented code,
* Fiber aware Multi-request interface for any callback enabled clients
* Fiber aware TCPSocket replacement, powered by EventMachine
* Fiber aware Thread, Mutex, ConditionVariable clases
- * Fiber aware sleep
+ * Fiber aware sleep, defer
Supported clients:
View
8 lib/em-synchrony.rb
@@ -98,6 +98,14 @@ def self.add_periodic_timer(interval, &blk)
def self.next_tick(&blk)
EM.next_tick { Fiber.new { blk.call }.resume }
end
+
+ # Fiber-aware EM.defer
+ #
+ def self.defer op = nil, &blk
+ fiber = Fiber.current
+ EM.defer(op || blk, lambda{ |result| fiber.resume(result) })
+ Fiber.yield
+ end
# Routes to EM::Synchrony::Keyboard
#
View
40 spec/defer_spec.rb
@@ -0,0 +1,40 @@
+require "spec/helper/all"
+
+describe EventMachine::Synchrony do
+
+ it "defer: simple" do
+ EM.synchrony do
+ x = 1
+
+ result = EM::Synchrony.defer do
+ x = 2
+ sleep 0.1
+ 3
+ end
+
+ result.should == 3
+ x.should == 2
+
+ EM.stop
+ end
+ end
+
+ it "defer: with lambda" do
+ EM.synchrony do
+
+ x = 1
+
+ op = lambda do
+ sleep 0.1
+ x += 1
+ 3
+ end
+
+ EM::Synchrony.defer(op).should == 3
+ x.should == 2
+
+ EM.stop
+ end
+ end
+
+end

No commit comments for this range

Something went wrong with that request. Please try again.