em-easy 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/README.rdoc +59 -0
  2. data/VERSION +1 -1
  3. data/gemspec.yml +13 -0
  4. metadata +7 -5
@@ -0,0 +1,59 @@
1
+ Easy asynchronous programming.
2
+
3
+ == Installation
4
+
5
+ gem install em-easy
6
+
7
+ == Introduction
8
+
9
+ In ruby land there is an awesome library for asynchronous stuff it's called EventedMachine.
10
+ But EventMachine lacks the ability to transparently mix with synchronous code, which can be handy in number of situations where you need to have more granular control over flow of your program or if you prefer a more traditional syntax.
11
+ There is a gem called em-synchrony which tries to overcome this problem quite successfully, but em-easy tries to simplify syntax even further.
12
+
13
+ == Example
14
+
15
+ require 'em-easy'
16
+ require 'em-http' # this is a separate library used in example
17
+
18
+ # you can use calls to EM asynchronous methods anywhere in your code
19
+ # they will be started immediately in background
20
+ request = EM::HttpRequest.new("http://darberry.ru").get
21
+ requests = Array.new(10) { EM::HttpRequest.new("http://www.postrank.com").get }
22
+
23
+ "..." # you can do anything while asynchronous operations are running in background
24
+
25
+ # if we need a result of request we wait for it or get it immediately if it's already finished
26
+ result = wait request
27
+
28
+ # so what do we do if we need results for array of requests?
29
+ # we can use already mentioned "wait" method
30
+ results = requests.map {|it| wait it }
31
+
32
+ # using wait method, requests are made in background in asynchronous manner, so it will yield a good performance
33
+ # but blocks of code for every result will be run serially, from the first request till the last
34
+ # but what if a first request will be a slow one and the rest of requests will be finished much more sooner
35
+ # in this case if the order of results doesn't matter you can use async method which works for any enumerable
36
+ # async calls block of code for enumerable method as soon as a new request is finished
37
+ results = requests.async.map do |result|
38
+ "..." # some long computations
39
+ end
40
+
41
+ # async returns an enumerator which works with any enumerable method, eg
42
+ results = requests.async.to_a
43
+
44
+ First, we can notice absence of usual EM.run and EM.stop calls. You don't have to think in such terms anymore.
45
+ Second, we can notice two new methods: Kernel#wait and Enumerable#async.
46
+
47
+ Kernel#wait blocks and returns result of asynchronous operation as soon as it available.
48
+ Enumerable#async returns Async::Enumerator. You can call any enumerable method on the enumerator and supplied block will be run in asynchronous manner as soon as new callback is fired, until all callbacks are fired execution of you program is blocked.
49
+
50
+ == Thanks
51
+
52
+ Christopher Bertels aka bakkdoor - initial idea as prototype for fancy language
53
+ Mike Perham aka mperham, Ilya Grigorik aka igrigorik - inspiration with awesome evented libraries
54
+
55
+ == Author
56
+
57
+ brainopia (ravwar at gmail.com).
58
+
59
+ I am always happy to chat about anything.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.1.2
@@ -0,0 +1,13 @@
1
+ name: em-easy
2
+ summary: Asynchronous programming (based on EventMachine) without trouble of callbacks
3
+ description:
4
+ You dont have to think in terms of EM.run and EM.stop anymore.
5
+ Simple and intuitive api which can be used in synchronous manner without dealing with callbacks.
6
+ More detailes at project homepage.
7
+
8
+ authors: brainopia
9
+ email: ravwar@gmail.com
10
+ homepage: http://github.com/brainopia/em-easy
11
+
12
+ dependencies:
13
+ eventmachine: ~> 0.12.10
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 1
9
- version: 0.1.1
8
+ - 2
9
+ version: 0.1.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - brainopia
@@ -32,16 +32,18 @@ dependencies:
32
32
  version: 0.12.10
33
33
  type: :runtime
34
34
  version_requirements: *id001
35
- description: Asynchronous programming (based on EventMachine) without trouble of callbacks
35
+ description: You dont have to think in terms of EM.run and EM.stop anymore. Simple and intuitive api which can be used in synchronous manner without dealing with callbacks. More detailes at project homepage.
36
36
  email: ravwar@gmail.com
37
37
  executables: []
38
38
 
39
39
  extensions: []
40
40
 
41
- extra_rdoc_files: []
42
-
41
+ extra_rdoc_files:
42
+ - README.rdoc
43
43
  files:
44
+ - README.rdoc
44
45
  - VERSION
46
+ - gemspec.yml
45
47
  - lib/em-easy.rb
46
48
  - lib/em-easy/extensions/enumerable.rb
47
49
  - lib/em-easy/extensions/kernel.rb