File: configurations.rb

package info (click to toggle)
ruby-celluloid 0.18.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 848 kB
  • sloc: ruby: 7,579; makefile: 10
file content (78 lines) | stat: -rw-r--r-- 1,949 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
require "celluloid"

puts "Use Supervision::Configuration objects!"

class Hello
  include Celluloid

  finalizer :ceasing

  def initialize(to)
    @to = to
    puts "Created Hello #{@to}"
  end

  def ceasing
    puts "Hello #{@to} go buhbye"
  end
end

class FooBar
  include Celluloid

  finalizer :ceasing

  def initialize(i = 0)
    @i = i
    puts "Created FooBar: #{@i}"
  end

  def ceasing
    puts "FooBar FooBar: #{@i} go buhbye"
  end
end

puts "\nInstantiated in bulk, using #deploy"

config = Celluloid::Supervision::Configuration.define([
                                                        { type: FooBar, as: :foobar },
                                                        { type: Hello, as: :hello, args: ["World"] }
                                                      ])

config.deploy
puts "...shut it down"
config.shutdown

puts "\nInstantiated in bulk, using .deploy"

config = Celluloid::Supervision::Configuration.deploy([
                                                        { type: FooBar, as: :foobar, args: [1] },
                                                        { type: Hello, as: :hello, args: ["World"] }
                                                      ])

puts "...shut it down"
config.shutdown

puts "\nInstantiated two actors individually, using a local configuration object"

config = Celluloid::Supervision::Configuration.new
config.define type: FooBar, as: :foobar11, args: [11]
config.define type: FooBar, as: :foobar33, args: [33]
config.deploy

puts "Instantiated another, which starts automatically."
puts "... using the local configuration object"
puts "... using a lazy loaded argument"
config.add type: Hello, as: :hello, args: -> { "Spinning World" }

config.shutdown

puts "\nReuse our last configuration!"

config.deploy
puts "...shut it down"
config.shutdown

puts "Thinking for 4 seconds, and 4 seconds only."
sleep 4
puts "Use Supervision::Configuration objects. Really!"