io-dispatcher 0.1

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: d281352f7399d0dde0548bf8afa4c56036d6fe76819bee60fda6a31ce642aae1
4
+ data.tar.gz: f870ec81b85111940779fbc13c9549cfe1bfec2842bc5c01c1b614d593ea53fe
5
+ SHA512:
6
+ metadata.gz: 8258030ec520c846ac7496c3c20d321ff1a6a60127d77c6f473ceb180c490e196a10b0e0dfe01f8b0aec6f77627767917b06d787117c1f2e847dc98cc63842ef
7
+ data.tar.gz: e898b8b9d29f78b18a91a32deacd3eca79cab26895cd51be2c8334fbae2aace4eb268816de9125f96002475a1946138b00d47d97288495b87ffe1e4272c1ce63
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ .DS_Store
2
+ *.gem
data/README.md ADDED
@@ -0,0 +1 @@
1
+ FIXME
data/Rakefile ADDED
@@ -0,0 +1,3 @@
1
+ require 'rubygems/tasks'
2
+
3
+ Gem::Tasks.new
@@ -0,0 +1,21 @@
1
+ require_relative 'lib/io-dispatcher/version'
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = 'io-dispatcher'
5
+ s.version = IO::Dispatcher::VERSION
6
+ s.summary = 'Simple dispatcher for IO objects.'
7
+ s.author = 'John Labovitz'
8
+ s.email = 'johnl@johnlabovitz.com'
9
+ s.description = %q{
10
+ IO::Dispatcher is a simple dispatcher for IO objects.
11
+ }
12
+ s.license = 'MIT'
13
+ s.homepage = 'http://github.com/jslabovitz/io-dispatcher'
14
+ s.files = `git ls-files`.split("\n")
15
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
+ s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
17
+ s.require_path = 'lib'
18
+
19
+ s.add_development_dependency 'rake', '~> 12.3'
20
+ s.add_development_dependency 'rubygems-tasks', '~> 0.2'
21
+ end
@@ -0,0 +1,5 @@
1
+ class IO::Dispatcher
2
+
3
+ VERSION = '0.1'
4
+
5
+ end
@@ -0,0 +1,40 @@
1
+ class IO
2
+
3
+ class Dispatcher
4
+
5
+ def initialize
6
+ @io_handlers = [{}, {}, {}]
7
+ @timeout = nil
8
+ end
9
+
10
+ def add_io_handler(input: nil, output: nil, exception: nil, handler: nil, &block)
11
+ mode, io = if input
12
+ [0, input]
13
+ elsif output
14
+ [1, output]
15
+ elsif exception
16
+ [2, exception]
17
+ end
18
+ @io_handlers[mode][io] = handler || block
19
+ end
20
+
21
+ def set_timeout_handler(timeout, &block)
22
+ @timeout = timeout
23
+ @timeout_handler = block
24
+ end
25
+
26
+ def run
27
+ loop do
28
+ if (ready = IO.select(*@io_handlers.map(&:keys), @timeout))
29
+ ready.each_with_index do |mode, i|
30
+ mode.each { |io| @io_handlers[i][io].call(io) }
31
+ end
32
+ else
33
+ @timeout_handler.call if @timeout_handler
34
+ end
35
+ end
36
+ end
37
+
38
+ end
39
+
40
+ end
metadata ADDED
@@ -0,0 +1,77 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: io-dispatcher
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ platform: ruby
6
+ authors:
7
+ - John Labovitz
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-03-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '12.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '12.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rubygems-tasks
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.2'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.2'
41
+ description: "\n IO::Dispatcher is a simple dispatcher for IO objects.\n "
42
+ email: johnl@johnlabovitz.com
43
+ executables: []
44
+ extensions: []
45
+ extra_rdoc_files: []
46
+ files:
47
+ - ".gitignore"
48
+ - README.md
49
+ - Rakefile
50
+ - io-dispatcher.gemspec
51
+ - lib/io-dispatcher.rb
52
+ - lib/io-dispatcher/version.rb
53
+ homepage: http://github.com/jslabovitz/io-dispatcher
54
+ licenses:
55
+ - MIT
56
+ metadata: {}
57
+ post_install_message:
58
+ rdoc_options: []
59
+ require_paths:
60
+ - lib
61
+ required_ruby_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ required_rubygems_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ requirements: []
72
+ rubyforge_project:
73
+ rubygems_version: 2.7.6
74
+ signing_key:
75
+ specification_version: 4
76
+ summary: Simple dispatcher for IO objects.
77
+ test_files: []