README.md in em-synchrony-1.0.4 vs README.md in em-synchrony-1.0.5
- old
+ new
@@ -1,9 +1,10 @@
# EM-Synchrony
[![Gem Version](https://badge.fury.io/rb/em-synchrony.png)](http://rubygems.org/gems/em-synchrony)
[![Analytics](https://ga-beacon.appspot.com/UA-71196-10/em-synchrony/readme)](https://github.com/igrigorik/ga-beacon)
+[![Build Status](https://travis-ci.org/igrigorik/em-synchrony.svg?branch=master)](https://travis-ci.org/igrigorik/em-synchrony)
Collection of convenience classes and primitives to help untangle evented code, plus a number of patched EM clients to make them Fiber aware. To learn more, please see: [Untangling Evented Code with Ruby Fibers](http://www.igvita.com/2010/03/22/untangling-evented-code-with-ruby-fibers).
* Fiber aware ConnectionPool with sync/async query support
* Fiber aware Iterator to allow concurrency control & mixing of sync / async
@@ -168,9 +169,34 @@
:adapter => 'em_mysql2',
:database => 'widgets'
)
result = Widget.all.to_a
+```
+
+## Hooks
+
+em-synchrony already provides fiber-aware calls for sleep, system and defer. When mixing fiber-aware code with other gems, these might use non-fiber-aware versions which result in unexpected behavior: calling `sleep` would pause the whole reactor instead of
+a single fiber. For that reason, hooks into the Kernel are provided to override the default behavior to e.g. add logging or redirect these calls their fiber-aware versions.
+
+```ruby
+# Adding logging but still executes the actual sleep
+require "em-synchrony"
+log = Logger.new(STDOUT)
+EM::Synchrony.on_sleep do |*args|
+ log.warn "Kernel.sleep called by:"
+ caller.each { |line| log.warn line }
+ sleep(*args) # Calls the actual sleep
+end
+```
+
+```ruby
+# Redirects to EM::Synchrony.sleep
+require "em-synchrony"
+log = Logger.new(STDOUT)
+EM::Synchrony.on_sleep do |*args|
+ EM::Synchrony.sleep(*args)
+end
```
# License
The MIT License - Copyright (c) 2011 Ilya Grigorik