celluloid 0.16.0 → 0.17.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of celluloid might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/CHANGES.md +333 -0
- data/README.md +1 -1
- data/culture/CODE_OF_CONDUCT.md +28 -0
- data/culture/Gemfile +9 -0
- data/culture/README.md +22 -0
- data/culture/Rakefile +5 -0
- data/culture/SYNC.md +70 -0
- data/culture/celluloid-culture.gemspec +18 -0
- data/culture/gems/README.md +39 -0
- data/culture/gems/dependencies.yml +78 -0
- data/culture/gems/loader.rb +101 -0
- data/culture/rubocop/README.md +38 -0
- data/culture/rubocop/lint.yml +8 -0
- data/culture/rubocop/metrics.yml +15 -0
- data/culture/rubocop/rubocop.yml +4 -0
- data/culture/rubocop/style.yml +48 -0
- data/culture/spec/gems_spec.rb +2 -0
- data/culture/spec/spec_helper.rb +0 -0
- data/culture/spec/sync_spec.rb +2 -0
- data/culture/sync.rb +56 -0
- data/culture/tasks/rspec.rake +5 -0
- data/culture/tasks/rubocop.rake +2 -0
- data/examples/basic_usage.rb +49 -0
- data/examples/futures.rb +38 -0
- data/examples/ring.rb +61 -0
- data/examples/simple_pmap.rb +14 -0
- data/examples/timers.rb +72 -0
- data/lib/celluloid.rb +142 -127
- data/lib/celluloid/actor.rb +47 -41
- data/lib/celluloid/actor_system.rb +75 -22
- data/lib/celluloid/autostart.rb +1 -1
- data/lib/celluloid/backported.rb +2 -0
- data/lib/celluloid/call/async.rb +16 -0
- data/lib/celluloid/call/block.rb +22 -0
- data/lib/celluloid/call/sync.rb +70 -0
- data/lib/celluloid/calls.rb +25 -114
- data/lib/celluloid/cell.rb +32 -20
- data/lib/celluloid/condition.rb +3 -3
- data/lib/celluloid/core_ext.rb +1 -1
- data/lib/celluloid/current.rb +2 -0
- data/lib/celluloid/deprecate.rb +18 -0
- data/lib/celluloid/exceptions.rb +1 -1
- data/lib/celluloid/fiber.rb +3 -3
- data/lib/celluloid/future.rb +7 -6
- data/lib/celluloid/group.rb +65 -0
- data/lib/celluloid/group/manager.rb +27 -0
- data/lib/celluloid/group/pool.rb +125 -0
- data/lib/celluloid/group/spawner.rb +71 -0
- data/lib/celluloid/logging.rb +5 -5
- data/lib/celluloid/mailbox.rb +14 -13
- data/lib/celluloid/mailbox/evented.rb +76 -0
- data/lib/celluloid/notices.rb +15 -0
- data/lib/celluloid/proxies.rb +12 -0
- data/lib/celluloid/proxy/abstract.rb +24 -0
- data/lib/celluloid/proxy/actor.rb +46 -0
- data/lib/celluloid/proxy/async.rb +36 -0
- data/lib/celluloid/proxy/block.rb +31 -0
- data/lib/celluloid/proxy/cell.rb +76 -0
- data/lib/celluloid/proxy/future.rb +40 -0
- data/lib/celluloid/proxy/sync.rb +44 -0
- data/lib/celluloid/rspec.rb +9 -10
- data/lib/celluloid/system_events.rb +16 -15
- data/lib/celluloid/{tasks.rb → task.rb} +21 -21
- data/lib/celluloid/task/fibered.rb +45 -0
- data/lib/celluloid/task/threaded.rb +59 -0
- data/lib/celluloid/test.rb +1 -1
- data/lib/celluloid/thread.rb +6 -1
- data/lib/celluloid/version.rb +3 -0
- data/spec/celluloid/actor_spec.rb +2 -2
- data/spec/celluloid/actor_system_spec.rb +35 -21
- data/spec/celluloid/block_spec.rb +3 -5
- data/spec/celluloid/calls_spec.rb +33 -11
- data/spec/celluloid/condition_spec.rb +16 -13
- data/spec/celluloid/evented_mailbox_spec.rb +1 -31
- data/spec/celluloid/future_spec.rb +13 -10
- data/spec/celluloid/group/elastic_spec.rb +0 -0
- data/spec/celluloid/group/manager_spec.rb +0 -0
- data/spec/celluloid/group/pool_spec.rb +8 -0
- data/spec/celluloid/group/spawner_spec.rb +8 -0
- data/spec/celluloid/mailbox/evented_spec.rb +27 -0
- data/spec/celluloid/mailbox_spec.rb +1 -3
- data/spec/celluloid/misc/leak_spec.rb +73 -0
- data/spec/celluloid/task/fibered_spec.rb +5 -0
- data/spec/celluloid/task/threaded_spec.rb +5 -0
- data/spec/celluloid/timer_spec.rb +14 -16
- data/spec/deprecate/actor_system_spec.rb +72 -0
- data/spec/deprecate/block_spec.rb +52 -0
- data/spec/deprecate/calls_spec.rb +57 -0
- data/spec/deprecate/evented_mailbox_spec.rb +34 -0
- data/spec/deprecate/future_spec.rb +32 -0
- data/spec/deprecate/internal_pool_spec.rb +4 -0
- data/spec/shared/actor_examples.rb +1237 -0
- data/spec/shared/group_examples.rb +121 -0
- data/{lib/celluloid/rspec → spec/shared}/mailbox_examples.rb +20 -17
- data/{lib/celluloid/rspec → spec/shared}/task_examples.rb +9 -8
- data/spec/spec_helper.rb +72 -16
- data/spec/support/coverage.rb +4 -0
- data/spec/support/crash_checking.rb +68 -0
- data/spec/support/debugging.rb +31 -0
- data/spec/support/env.rb +16 -0
- data/{lib/celluloid/rspec/example_actor_class.rb → spec/support/examples/actor_class.rb} +21 -2
- data/spec/support/examples/evented_mailbox_class.rb +27 -0
- data/spec/support/includer.rb +9 -0
- data/spec/support/logging.rb +63 -0
- data/spec/support/loose_threads.rb +65 -0
- data/spec/support/reset_class_variables.rb +27 -0
- data/spec/support/sleep_and_wait.rb +14 -0
- data/spec/support/split_logs.rb +1 -0
- data/spec/support/stubbing.rb +14 -0
- metadata +255 -95
- data/lib/celluloid/call_chain.rb +0 -13
- data/lib/celluloid/cpu_counter.rb +0 -34
- data/lib/celluloid/evented_mailbox.rb +0 -73
- data/lib/celluloid/fsm.rb +0 -186
- data/lib/celluloid/handlers.rb +0 -41
- data/lib/celluloid/internal_pool.rb +0 -159
- data/lib/celluloid/legacy.rb +0 -9
- data/lib/celluloid/links.rb +0 -36
- data/lib/celluloid/logger.rb +0 -93
- data/lib/celluloid/logging/incident.rb +0 -21
- data/lib/celluloid/logging/incident_logger.rb +0 -129
- data/lib/celluloid/logging/incident_reporter.rb +0 -48
- data/lib/celluloid/logging/log_event.rb +0 -20
- data/lib/celluloid/logging/ring_buffer.rb +0 -65
- data/lib/celluloid/method.rb +0 -32
- data/lib/celluloid/notifications.rb +0 -83
- data/lib/celluloid/pool_manager.rb +0 -146
- data/lib/celluloid/probe.rb +0 -73
- data/lib/celluloid/properties.rb +0 -24
- data/lib/celluloid/proxies/abstract_proxy.rb +0 -20
- data/lib/celluloid/proxies/actor_proxy.rb +0 -38
- data/lib/celluloid/proxies/async_proxy.rb +0 -31
- data/lib/celluloid/proxies/block_proxy.rb +0 -29
- data/lib/celluloid/proxies/cell_proxy.rb +0 -68
- data/lib/celluloid/proxies/future_proxy.rb +0 -35
- data/lib/celluloid/proxies/sync_proxy.rb +0 -36
- data/lib/celluloid/receivers.rb +0 -63
- data/lib/celluloid/registry.rb +0 -57
- data/lib/celluloid/responses.rb +0 -44
- data/lib/celluloid/rspec/actor_examples.rb +0 -1054
- data/lib/celluloid/signals.rb +0 -23
- data/lib/celluloid/stack_dump.rb +0 -133
- data/lib/celluloid/supervision_group.rb +0 -169
- data/lib/celluloid/supervisor.rb +0 -22
- data/lib/celluloid/task_set.rb +0 -49
- data/lib/celluloid/tasks/task_fiber.rb +0 -43
- data/lib/celluloid/tasks/task_thread.rb +0 -53
- data/lib/celluloid/thread_handle.rb +0 -50
- data/lib/celluloid/uuid.rb +0 -38
- data/spec/celluloid/cpu_counter_spec.rb +0 -82
- data/spec/celluloid/fsm_spec.rb +0 -107
- data/spec/celluloid/internal_pool_spec.rb +0 -52
- data/spec/celluloid/links_spec.rb +0 -45
- data/spec/celluloid/logging/ring_buffer_spec.rb +0 -38
- data/spec/celluloid/notifications_spec.rb +0 -120
- data/spec/celluloid/pool_spec.rb +0 -92
- data/spec/celluloid/probe_spec.rb +0 -121
- data/spec/celluloid/properties_spec.rb +0 -42
- data/spec/celluloid/registry_spec.rb +0 -64
- data/spec/celluloid/stack_dump_spec.rb +0 -64
- data/spec/celluloid/supervision_group_spec.rb +0 -65
- data/spec/celluloid/supervisor_spec.rb +0 -103
- data/spec/celluloid/tasks/task_fiber_spec.rb +0 -5
- data/spec/celluloid/tasks/task_thread_spec.rb +0 -5
- data/spec/celluloid/thread_handle_spec.rb +0 -26
- data/spec/celluloid/uuid_spec.rb +0 -11
@@ -0,0 +1,18 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = "celluloid-culture"
|
5
|
+
spec.version = "0.1.1"
|
6
|
+
spec.authors = ["Tony Arcieri"]
|
7
|
+
spec.email = ["bascule@gmail.com"]
|
8
|
+
|
9
|
+
spec.summary = "The culture of Celluloid, in RubyGem form!"
|
10
|
+
spec.description = "In which we try to codify Celluloid's life philosophy as Ruby"
|
11
|
+
spec.homepage = "https://github.com/celluloid/culture"
|
12
|
+
|
13
|
+
spec.files = Dir["README.md", "CHANGES.md", "LICENSE.txt", "lib/**/*", "spec/**/*"]
|
14
|
+
spec.require_path = "lib"
|
15
|
+
|
16
|
+
spec.add_development_dependency "bundler", "~> 1.9"
|
17
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
18
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# Motivation
|
2
|
+
To achieve the higher level of modularity, Celluloid was split into small sub-projects that naturally depend on each other.
|
3
|
+
Bundler can't handle circular dependencies properly and currently the only workaround is to list all celluloid-ish dependencies in both Gemfile and gemspec.
|
4
|
+
This is error-prone and not efficient. Thus it was required to put some better workaround in place.
|
5
|
+
|
6
|
+
# Configuration
|
7
|
+
The list of gems and their properties are now defined in `dependencies.yml`.
|
8
|
+
|
9
|
+
For example:
|
10
|
+
|
11
|
+
```yml
|
12
|
+
celluloid:
|
13
|
+
bundler:
|
14
|
+
github: celluloid/celluloid
|
15
|
+
branch: 0.17.0-prerelease
|
16
|
+
celluloid-extras:
|
17
|
+
bundler:
|
18
|
+
github: celluloid/celluloid-extras
|
19
|
+
celluloid-supervision:
|
20
|
+
bundler:
|
21
|
+
github: celluloid/celluloid-supervision
|
22
|
+
celluloid-pool:
|
23
|
+
bundler:
|
24
|
+
github: celluloid/celluloid-pool
|
25
|
+
celluloid-fsm:
|
26
|
+
bundler:
|
27
|
+
github: celluloid/celluloid-fsm
|
28
|
+
timers:
|
29
|
+
gemspec:
|
30
|
+
- ~> 4.0.0
|
31
|
+
bundler:
|
32
|
+
github: celluloid/timers
|
33
|
+
```
|
34
|
+
|
35
|
+
# Modification of `gemspec` and `Gemfile`
|
36
|
+
|
37
|
+
The injection of dependencies into `gemspec` and `Gemfile` is handled by `Celluloid::Sync.gems()`, which routes to either `Celluloid::Gems.gemspec` or `Celluloid::Gems.gemfile` depending on what is passed to it:
|
38
|
+
|
39
|
+
* Discussed in [SYNC.md](../SYNC.md#how-do-you-install-it-in-gemfile-and-gemspec-then)
|
@@ -0,0 +1,78 @@
|
|
1
|
+
bundler:
|
2
|
+
nenv:
|
3
|
+
dotenv:
|
4
|
+
|
5
|
+
benchmark_suite:
|
6
|
+
dependency: development
|
7
|
+
|
8
|
+
rubocop:
|
9
|
+
dependency: development
|
10
|
+
|
11
|
+
pry:
|
12
|
+
dependency: development
|
13
|
+
|
14
|
+
rake:
|
15
|
+
dependency: development
|
16
|
+
|
17
|
+
rspec:
|
18
|
+
dependency: development
|
19
|
+
|
20
|
+
coveralls:
|
21
|
+
dependency: development
|
22
|
+
gemfile:
|
23
|
+
require: false
|
24
|
+
|
25
|
+
celluloid:
|
26
|
+
dependency: core
|
27
|
+
version: ">= 0.17.0.pre12"
|
28
|
+
gemfile:
|
29
|
+
github: celluloid/celluloid
|
30
|
+
branch: 0.17.0-prerelease
|
31
|
+
submodules: true
|
32
|
+
|
33
|
+
celluloid-essentials:
|
34
|
+
dependency: module
|
35
|
+
gemfile:
|
36
|
+
github: celluloid/celluloid-essentials
|
37
|
+
branch: master
|
38
|
+
submodules: true
|
39
|
+
|
40
|
+
celluloid-supervision:
|
41
|
+
dependency: module
|
42
|
+
gemfile:
|
43
|
+
github: celluloid/celluloid-supervision
|
44
|
+
branch: master
|
45
|
+
submodules: true
|
46
|
+
|
47
|
+
celluloid-pool:
|
48
|
+
dependency: module
|
49
|
+
gemfile:
|
50
|
+
github: celluloid/celluloid-pool
|
51
|
+
branch: master
|
52
|
+
submodules: true
|
53
|
+
|
54
|
+
celluloid-fsm:
|
55
|
+
dependency: module
|
56
|
+
gemfile:
|
57
|
+
github: celluloid/celluloid-fsm
|
58
|
+
branch: master
|
59
|
+
submodules: true
|
60
|
+
|
61
|
+
celluloid-extras:
|
62
|
+
dependency: module
|
63
|
+
gemfile:
|
64
|
+
github: celluloid/celluloid-extras
|
65
|
+
branch: master
|
66
|
+
submodules: true
|
67
|
+
|
68
|
+
timers:
|
69
|
+
version: "~> 4.0.0"
|
70
|
+
gemfile:
|
71
|
+
github: celluloid/timers
|
72
|
+
|
73
|
+
rspec-logsplit:
|
74
|
+
version: ">= 0.1.2"
|
75
|
+
gemfile:
|
76
|
+
github: "abstractive/rspec-logsplit"
|
77
|
+
branch: "master"
|
78
|
+
require: false
|
@@ -0,0 +1,101 @@
|
|
1
|
+
require "yaml"
|
2
|
+
|
3
|
+
module Celluloid
|
4
|
+
module Sync
|
5
|
+
module Gemfile
|
6
|
+
class << self
|
7
|
+
def [](dsl)
|
8
|
+
dsl.source("https://rubygems.org")
|
9
|
+
dsl.gemspec # Runs gemspec, but also @sets gem_name.
|
10
|
+
Gems.gemfile(dsl)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
module Gemspec
|
15
|
+
class << self
|
16
|
+
def [](gem)
|
17
|
+
Gems.gemspec(gem)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
module Gems
|
23
|
+
extend self
|
24
|
+
@gem_name = nil
|
25
|
+
|
26
|
+
undef gems rescue nil
|
27
|
+
def gems
|
28
|
+
File.expand_path("../dependencies.yml", __FILE__)
|
29
|
+
end
|
30
|
+
|
31
|
+
unless @dependencies ||= nil
|
32
|
+
@dependencies = YAML.load_file(gems) if File.exist?(gems)
|
33
|
+
end
|
34
|
+
|
35
|
+
unless @dependencies.is_a?(Hash) && @dependencies.any?
|
36
|
+
fail "Celluloid cannot find its dependencies."
|
37
|
+
end
|
38
|
+
|
39
|
+
undef core? rescue nil
|
40
|
+
def core?(name=@gem_name)
|
41
|
+
return false unless @dependencies[name].is_a? Hash
|
42
|
+
@dependencies[name]["dependency"] == "core"
|
43
|
+
end
|
44
|
+
|
45
|
+
undef separate? rescue nil
|
46
|
+
def separate?
|
47
|
+
!@dependencies.keys.include?(@gem_name)
|
48
|
+
end
|
49
|
+
|
50
|
+
undef gemspec rescue nil
|
51
|
+
def gemspec(gem)
|
52
|
+
@gem_name = gem.name
|
53
|
+
loader do |name, spec|
|
54
|
+
# Rules for dependencies, to avoid so-called circular dependency:
|
55
|
+
# - Only the core gem lists all the modules as runtime dependencies.
|
56
|
+
# - If this gem is not in the dependencies list, then it needs the core gem at runtime;
|
57
|
+
# the module gems are development dependencies only. This is a depending separate gem.
|
58
|
+
# There is the core gem, module gems, true dependencies, and separately depending gems.
|
59
|
+
# - If the dependency is a module, it is only a development dependency to other modules,
|
60
|
+
# and even the core gem is a development dependency. It is not expected to be used alone.
|
61
|
+
meth = case spec["dependency"]
|
62
|
+
when "core", "module"
|
63
|
+
# For the core gem, all modules are runtime dependencies.
|
64
|
+
# For separate gems, only the core gem is a runtime dependency.
|
65
|
+
if core? || (separate? && core?(name))
|
66
|
+
:add_runtime_dependency
|
67
|
+
else
|
68
|
+
:add_development_dependency
|
69
|
+
end
|
70
|
+
when "development"
|
71
|
+
:add_development_dependency
|
72
|
+
else
|
73
|
+
:add_dependency
|
74
|
+
end
|
75
|
+
gem.send(meth, name, spec["version"] || ">= 0")
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
undef gemfile rescue nil
|
80
|
+
def gemfile(dsl)
|
81
|
+
loader do |name, spec|
|
82
|
+
params = [name, spec["version"] || ">= 0"]
|
83
|
+
req = spec["gemfile"] || {}
|
84
|
+
params << req.each_with_object({}) { |(k, v), o| o[k.to_sym] = v }
|
85
|
+
current = dsl.dependencies.find { |d| d.name == name }
|
86
|
+
dsl.dependencies.delete(current) if current
|
87
|
+
dsl.gem(*params)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
private
|
92
|
+
|
93
|
+
def loader
|
94
|
+
@dependencies.each do |name, spec|
|
95
|
+
next if name == @gem_name
|
96
|
+
spec ||= {}
|
97
|
+
yield name, spec
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# About
|
2
|
+
[RuboCop](https://github.com/bbatsov/rubocop) is a ruby static code analyzer.
|
3
|
+
It's more than just a lint. It verifies the code against ruby best practices and performs code correctness analysis.
|
4
|
+
Celluloid culture doesn't always agree with all rubocop default policies and so we provide a rubocop configuration file that overrides its default behavior.
|
5
|
+
|
6
|
+
# Integration
|
7
|
+
|
8
|
+
[Integrate `celluloid/culture`](../README.md#integration), then include `culture/rupocop/.rubocop.yml` in your default rubocop config.
|
9
|
+
|
10
|
+
##### Add celluloid/culture as GIT submodule:
|
11
|
+
|
12
|
+
* See instructions: [Integrate the `celluloid/culture` sub-module](../README.md#integration)
|
13
|
+
|
14
|
+
##### Include `culture/rupocop/rubocop.yml` in the `.rubocop.yml` in the root of your project:
|
15
|
+
```yml
|
16
|
+
inherit_from:
|
17
|
+
- culture/rubocop/rubocop.yml
|
18
|
+
```
|
19
|
+
|
20
|
+
# How to add rubocop to your project
|
21
|
+
|
22
|
+
The `rubocop` gem is automatically included by `Celluloid::Sync.gems` when that is [implemented](../SYNC.md).
|
23
|
+
|
24
|
+
##### Add a 'rubocop' target in your `Rakefile`
|
25
|
+
|
26
|
+
# Hints
|
27
|
+
It's possible to use rubocop for autocorrection of minor problems.
|
28
|
+
|
29
|
+
Always verify these changes by running:
|
30
|
+
|
31
|
+
```sh
|
32
|
+
bundle exec rubocop
|
33
|
+
```
|
34
|
+
|
35
|
+
Once you are ready to auto-corret the issues you are shown, run it with the `-a` option:
|
36
|
+
```sh
|
37
|
+
bundle exec rubocop -a
|
38
|
+
```
|
@@ -0,0 +1,48 @@
|
|
1
|
+
Style/Documentation:
|
2
|
+
Enabled: false
|
3
|
+
|
4
|
+
Style/ModuleFunction:
|
5
|
+
Enabled: false
|
6
|
+
|
7
|
+
Style/AndOr:
|
8
|
+
Enabled: true
|
9
|
+
|
10
|
+
Style/StringLiterals:
|
11
|
+
Enabled: true
|
12
|
+
EnforcedStyle: double_quotes
|
13
|
+
|
14
|
+
Style/EachWithObject:
|
15
|
+
Enabled: true
|
16
|
+
|
17
|
+
Style/InfiniteLoop:
|
18
|
+
Enabled: false
|
19
|
+
|
20
|
+
Style/SpaceAroundEqualsInParameterDefault:
|
21
|
+
Enabled: false
|
22
|
+
|
23
|
+
Style/SpaceInsideBlockBraces:
|
24
|
+
Enabled: false
|
25
|
+
|
26
|
+
Style/AccessModifierIndentation:
|
27
|
+
Enabled: false
|
28
|
+
|
29
|
+
Style/TrailingComma:
|
30
|
+
Enabled: true
|
31
|
+
EnforcedStyleForMultiline: comma
|
32
|
+
|
33
|
+
Style/SpaceInsideBlockBraces:
|
34
|
+
Enabled: true
|
35
|
+
EnforcedStyle: space
|
36
|
+
|
37
|
+
Style/SpaceInsideHashLiteralBraces:
|
38
|
+
Enabled: true
|
39
|
+
EnforcedStyle: no_space
|
40
|
+
|
41
|
+
Style/EmptyLinesAroundAccessModifier:
|
42
|
+
Enabled: false
|
43
|
+
|
44
|
+
Style/RescueModifier:
|
45
|
+
Enabled: false
|
46
|
+
|
47
|
+
Style/GlobalVars:
|
48
|
+
Enabled: false
|
File without changes
|
data/culture/sync.rb
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
require "forwardable"
|
2
|
+
|
3
|
+
module Celluloid
|
4
|
+
module Sync
|
5
|
+
class << self
|
6
|
+
undef gem_path rescue nil
|
7
|
+
def gem_path
|
8
|
+
File.expand_path("../../", __FILE__)
|
9
|
+
end
|
10
|
+
|
11
|
+
undef gem_name rescue nil
|
12
|
+
def gem_name
|
13
|
+
Dir["#{File.expand_path('../../', __FILE__)}/*.gemspec"].first.gsub(".gemspec", "").split("/").last
|
14
|
+
end
|
15
|
+
|
16
|
+
undef gem_name? rescue nil
|
17
|
+
def gem_name?
|
18
|
+
!gem_name.nil?
|
19
|
+
end
|
20
|
+
|
21
|
+
undef lib_path rescue nil
|
22
|
+
def lib_path
|
23
|
+
File.expand_path("../../lib", __FILE__)
|
24
|
+
end
|
25
|
+
|
26
|
+
undef lib_gempath rescue nil
|
27
|
+
def lib_gempath
|
28
|
+
"#{lib_path}/#{gem_name.split('-').join('/')}"
|
29
|
+
end
|
30
|
+
|
31
|
+
undef scenario rescue nil
|
32
|
+
def scenario
|
33
|
+
File.basename($PROGRAM_NAME)
|
34
|
+
end
|
35
|
+
|
36
|
+
undef bundler? rescue nil
|
37
|
+
def bundler?
|
38
|
+
scenario == "bundle"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
fail "Missing gemspec." unless gem_name?
|
43
|
+
$LOAD_PATH.push(gem_path)
|
44
|
+
$LOAD_PATH.push(lib_path)
|
45
|
+
|
46
|
+
# TODO: This will likely need to be done differently if INSIDE a cut gem.
|
47
|
+
if scenario == "bundle"
|
48
|
+
`cd #{gem_path}/culture; git pull origin master` if ARGV.first == "update"
|
49
|
+
end
|
50
|
+
|
51
|
+
require("#{gem_path}/culture/gems/loader")
|
52
|
+
if File.exist?(version = "#{lib_gempath}/version.rb")
|
53
|
+
require(version)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
$LOAD_PATH.push File.expand_path("../../lib", __FILE__)
|
4
|
+
require "celluloid/autostart"
|
5
|
+
|
6
|
+
class Counter
|
7
|
+
# This is all you have to do to turn any Ruby class into one which creates
|
8
|
+
# Celluloid actors instead of normal objects
|
9
|
+
include Celluloid
|
10
|
+
|
11
|
+
# Now just define methods like you ordinarily would
|
12
|
+
attr_reader :count
|
13
|
+
|
14
|
+
def initialize
|
15
|
+
@count = 0
|
16
|
+
end
|
17
|
+
|
18
|
+
def increment(n = 1)
|
19
|
+
@count += n
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
# Create objects just like you normally would. 'actor' is now a proxy object
|
24
|
+
# which talks to a Celluloid actor running in its own thread
|
25
|
+
actor = Counter.new
|
26
|
+
|
27
|
+
# The proxy obeys normal method invocation the way we'd expect. This prints 0
|
28
|
+
p actor.count
|
29
|
+
|
30
|
+
# This increments @count by 1 and prints 1
|
31
|
+
p actor.increment
|
32
|
+
|
33
|
+
# By using actor.async, you can make calls asynchronously. This immediately
|
34
|
+
# requests execution of method by sending a message, and we have no idea
|
35
|
+
# whether or not that request will actually complete because we don't wait
|
36
|
+
# for a response. Async calls immediately return nil regardless of how long
|
37
|
+
# the method takes to execute. Therefore, this will print nil.
|
38
|
+
p actor.async.increment 41
|
39
|
+
|
40
|
+
# In practice, the asynchronous call made above will increment the count before
|
41
|
+
# we get here. However, do not rely on this behavior! Asynchronous methods are
|
42
|
+
# inherently uncoordinated. If you need to coordinate asynchronous activities,
|
43
|
+
# you will need to use futures or FSMs. See the corresponding examples for those.
|
44
|
+
# Signals can also be used to coordinate asynchronous activities.
|
45
|
+
#
|
46
|
+
# The following line could possibly print either 1 or 42, depending on if the
|
47
|
+
# asynchronous call above completed. In practice, it prints 42 on all Ruby
|
48
|
+
# implementations because the asynchronous call above will always execute
|
49
|
+
p actor.count
|