Sha256: c169054cb2b7450fdc3a944852a2fb75abe06060ca354222f1096584c913d0d8
Contents?: true
Size: 1.31 KB
Versions: 1
Compression:
Stored size: 1.31 KB
Contents
require 'fsm' require 'fileutils' stager = FSM.system processer = FSM.system archiver = FSM.system stager.configure do fsm{ states %w( empty full ) transition 'filling', 'empty' => 'full' transition 'emptying', 'full' => 'empty' } observer{ on_entry 'empty' do transition 'empty', 'filling' do 2.times do |n| FileUtils.touch "a/#{ n }" puts "touch a/#{ n }" end end end } start end processer.configure do fsm{ states %w( empty processing full ) transition 'empty' => 'processing' transition 'processing' => 'full' transition 'full' => 'empty' } observer{ on_entry 'empty' do stager.observer.wait_for 'full' transition 'empty' do Dir["a/*"].each do |path| FileUtils.mv path, "b/" puts "#{ path } -->> b/" end end stager.transition 'full', 'emptying' end on_entry 'processing' do transition 'processing' do Dir["b/*"].each do |path| FileUtils.mv path, "c/" puts "#{ path } -->> c/" end end end } start end archiver.configure do fsm{ states %w( empty full ) transition 'filling', 'empty' => 'full' transition 'emptying', 'full' => 'empty' } observer{ } start end STDIN.gets
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
fsm-0.0.0 | sample/a.rb |