summaryrefslogtreecommitdiffstats
path: root/examples/hello_world.rb
blob: 69befd4dfa3118b451b585b432c5541f2a0041f3 (plain)
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
#! /usr/bin/env ruby
# -*- coding: UTF-8 -*-
#
# run from project top directory with : ruby -Ilib examples/hello_world.rb
#
require 'edoors'
#
class InputDoor < Edoors::Door
    #
    def start!
        # stimulate myself
        send_p require_p(Edoors::Particle), Edoors::ACT_GET
    end
    #
    def receive_p p
        if p.action==Edoors::ACT_GET
            p.reset!
            p.set_data 'txt', "hello world"
            send_p p    # will follow the default link
        else
            puts p.action
            # we can release it or let the Door do it
            release_p p
        end
    end
    #
end
#
class OutputDoor < Edoors::Door
    #
    def receive_p p
        puts p.get_data('txt')
        # let the door release it
    end
    #
end
#
if $0 == __FILE__
    #
    dom0 = Edoors::Spin.new 'dom0'
    input = InputDoor.new 'input', dom0
    output = OutputDoor.new 'output', dom0
    dom0.add_link Edoors::Link.new('input', 'output', nil, nil, nil)
    #
    dom0.spin!
    dom0.hibernate!
    #
end
#
# EOF