asynchro 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem 'eventmachine'
4
+
5
+ group :development do
6
+ gem "bundler"
7
+ gem "jeweler"
8
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Scott Tadman, The Working Group Inc.
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,115 @@
1
+ = asynchro
2
+
3
+ This is a set of extensions for Test::Unit::TestCase and any plain Ruby
4
+ classes that will be operating inside the EventMachine framework.
5
+
6
+ The two primary components are:
7
+
8
+ * A simple tracker that can be used to organize multiple independent blocks
9
+ and ensure that they are all completed before moving on.
10
+ * A simple state machine defining tool that can be used to map out the steps
11
+ required to complete an operation. This is especially useful if the process
12
+ will vary depending on certain conditions.
13
+
14
+ == State
15
+
16
+ To define a state mapping, include the Asynchro::Extensions methods and
17
+ then use the `async_state` method:
18
+
19
+ include Asynchro::Extensions
20
+ ran = [ ]
21
+
22
+ async_state do
23
+ start do
24
+ ran << :start
25
+ state1!
26
+ end
27
+
28
+ state1 do
29
+ ran << :state1
30
+ state2!
31
+ end
32
+
33
+ state2 do
34
+ ran << :state2
35
+ state3!
36
+ end
37
+
38
+ state3 do
39
+ ran << :state3
40
+ finish!
41
+ end
42
+
43
+ finish do
44
+ ran << :finish
45
+ end
46
+ end
47
+
48
+ At the end of this, the `ran` array will contain a list of all the states
49
+ which have executed, which in this example will be all of them in order.
50
+
51
+ The two pre-defined states are `start` and `finish`, where the default
52
+ behavior is to simply finish when started.
53
+
54
+ To declare a state, simply name it and supply a block to execute when
55
+ in that particular state. Generally the `start` state is defined first
56
+ in order to provide an entry point. The `finish` state is optional.
57
+
58
+ To transition to another state from within a state, call the name of
59
+ the state with the exclamation at the end, so for `finish` then `finish!`
60
+ would be called. Entering a state that has not been previously defined
61
+ will result in a warning being sent to STDERR for diagnostic purposes.
62
+
63
+ If this warning is undesirable, declare the state with an empty block.
64
+
65
+ Be careful to avoid entering states for which there is no exit condition
66
+ or the execution will never successfully complete.
67
+
68
+ == Tracker
69
+
70
+ The tracker component is used to process multiple blocks independently, yet
71
+ confirm that they have all completed before moving on. An example is:
72
+
73
+ include Asynchro::Extensions
74
+ success = false
75
+
76
+ async_tracker do
77
+ perform do |done|
78
+ done.call
79
+ end
80
+
81
+ perform(4) do |done|
82
+ 4.times do
83
+ done.call
84
+ end
85
+ end
86
+
87
+ finish do
88
+ success = true
89
+ end
90
+ end
91
+
92
+ The `perform` method is used to declare something that must be performed,
93
+ and the `finish` method will be executed once all of the declared blocks
94
+ have executed their callback.
95
+
96
+ The `perform` method takes a numerical argument that indicates the number of
97
+ times the callback must be called in order to be completed. The default is 1.
98
+ Negative or zero values will result in undefined behavior.
99
+
100
+ Just as multiple `perform` blocks can be declared, multiple `finish` blocks
101
+ can be supplied. These will execute in order, once, upon completion.
102
+
103
+ As there is no timeout, the tracker will wait for an indefinite period of
104
+ time if something precludes one or more of the callbacks from being executed.
105
+ This tracker is only suitable for asynchronous code that will always trigger
106
+ a callback of some sort within an acceptable period of time.
107
+
108
+ == Other Notes
109
+
110
+ Additional demonstrations of these are included in the test/ directory.
111
+
112
+ == Copyright
113
+
114
+ Copyright (c) 2011 Scott Tadman, The Working Group Inc. See LICENSE.txt for
115
+ further details.
data/Rakefile ADDED
@@ -0,0 +1,37 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+
6
+ begin
7
+ Bundler.setup(:default, :development)
8
+ rescue Bundler::BundlerError => e
9
+ $stderr.puts e.message
10
+ $stderr.puts "Run `bundle install` to install missing gems"
11
+ exit e.status_code
12
+ end
13
+
14
+ require 'rake'
15
+ require 'jeweler'
16
+
17
+ Jeweler::Tasks.new do |gem|
18
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
19
+ gem.name = "asynchro"
20
+ gem.homepage = "http://github.com/tadman/asynchro"
21
+ gem.license = "MIT"
22
+ gem.summary = %Q{Ruby EventMachine Async Programming Toolkit}
23
+ gem.description = %Q{Provides a number of tools to help make developing and testing asynchronous applications more manageable.}
24
+ gem.email = "github@tadman.ca"
25
+ gem.authors = [ "Scott Tadman" ]
26
+
27
+ # Additional dependencies are defined in the Gemfile
28
+ end
29
+ Jeweler::RubygemsDotOrgTasks.new
30
+
31
+ require 'rake/testtask'
32
+
33
+ Rake::TestTask.new(:test) do |test|
34
+ test.libs << 'lib' << 'test'
35
+ test.pattern = 'test/**/test_*.rb'
36
+ test.verbose = true
37
+ end
data/lib/asynchro.rb ADDED
@@ -0,0 +1,6 @@
1
+ module Asynchro
2
+ autoload(:Extensions, 'asynchro/extensions')
3
+ autoload(:State, 'asynchro/state')
4
+ autoload(:TestHelper, 'asynchro/test_helper')
5
+ autoload(:Tracker, 'asynchro/tracker')
6
+ end
data/test/helper.rb ADDED
@@ -0,0 +1,21 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+
4
+ begin
5
+ Bundler.setup(:default, :development)
6
+ rescue Bundler::BundlerError => e
7
+ $stderr.puts e.message
8
+ $stderr.puts "Run `bundle install` to install missing gems"
9
+ exit e.status_code
10
+ end
11
+
12
+ require 'test/unit'
13
+
14
+ $: << File.expand_path(File.join(*%w[ .. lib ]), File.dirname(__FILE__))
15
+ $: << File.dirname(__FILE__)
16
+
17
+ require 'asynchro'
18
+
19
+ class Test::Unit::TestCase
20
+ include Asynchro::TestHelper
21
+ end
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class TestAsynchro < Test::Unit::TestCase
4
+ def test_module
5
+ assert Asynchro
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,89 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: asynchro
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Scott Tadman
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-09-26 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: eventmachine
16
+ requirement: &2152536540 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *2152536540
25
+ - !ruby/object:Gem::Dependency
26
+ name: bundler
27
+ requirement: &2152535960 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *2152535960
36
+ - !ruby/object:Gem::Dependency
37
+ name: jeweler
38
+ requirement: &2152535400 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *2152535400
47
+ description: Provides a number of tools to help make developing and testing asynchronous
48
+ applications more manageable.
49
+ email: github@tadman.ca
50
+ executables: []
51
+ extensions: []
52
+ extra_rdoc_files:
53
+ - LICENSE.txt
54
+ - README.rdoc
55
+ files:
56
+ - .document
57
+ - Gemfile
58
+ - LICENSE.txt
59
+ - README.rdoc
60
+ - Rakefile
61
+ - lib/asynchro.rb
62
+ - test/helper.rb
63
+ - test/test_asynchro.rb
64
+ homepage: http://github.com/tadman/asynchro
65
+ licenses:
66
+ - MIT
67
+ post_install_message:
68
+ rdoc_options: []
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
+ none: false
79
+ requirements:
80
+ - - ! '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ requirements: []
84
+ rubyforge_project:
85
+ rubygems_version: 1.8.10
86
+ signing_key:
87
+ specification_version: 3
88
+ summary: Ruby EventMachine Async Programming Toolkit
89
+ test_files: []