amirka-async-fu 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. data/LICENSE +20 -0
  2. data/README.rdoc +53 -0
  3. data/VERSION.yml +4 -0
  4. data/lib/async_fu.rb +24 -0
  5. metadata +58 -0
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Amir Mamedov
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,53 @@
1
+ = async-fu
2
+
3
+ async-fu improve your code with abilities to run long task in threaded way
4
+
5
+
6
+ == Examples
7
+ === Simple usage
8
+ class YourClass1
9
+ def hello
10
+ p 'incapsulated test'
11
+ p 'start'
12
+ p 'list ' + Thread.list.join( ' ')
13
+ p 'main ' + Thread.main.to_s
14
+ p 'this ' + Thread.current.to_s
15
+ p 'end'
16
+ end
17
+ end
18
+
19
+ af = AsyncFu.new(YourClass1.new)
20
+
21
+ af.hello
22
+ === Interitence usage
23
+ class YourClass2 < AsyncFu
24
+ def hello
25
+ p 'start'
26
+ p 'list ' + Thread.list.join( ' ')
27
+ p 'main ' + Thread.main.to_s
28
+ p 'this ' + Thread.current.to_s
29
+ p 'end'
30
+ end
31
+ end
32
+
33
+ ai = YourClass2.new
34
+
35
+ ai.hello
36
+ === Thread exit solution
37
+ You do not need more to use join method to lock threads, if you not use it for some reasons.
38
+
39
+ AsyncFu catch exit of ruby program and check for live threads pass main thread until they ended.
40
+
41
+ If you don't need this futures, you can switch it off by using exit method of AsyncFu class.
42
+ == TODO
43
+ === 1.x.x
44
+ * callbacks
45
+
46
+ === 2.x.x
47
+ * add mixin style
48
+ YourClass
49
+ include async-fu
50
+ end
51
+ == Copyright
52
+
53
+ Copyright (c) 2009 Amir Mamedov. See LICENSE for details.
data/VERSION.yml ADDED
@@ -0,0 +1,4 @@
1
+ ---
2
+ :major: 1
3
+ :minor: 1
4
+ :patch: 0
data/lib/async_fu.rb ADDED
@@ -0,0 +1,24 @@
1
+ require 'fastthread'
2
+ class AsyncFu
3
+ def initialize(obj = nil)
4
+ @class = obj || self
5
+ @guard = Mutex.new
6
+ at_exit{
7
+ unless @exit
8
+ until Thread.list.size == 1 do Thread.pass end
9
+ end
10
+ }
11
+ end
12
+ def method_missing(name, *args)
13
+ if @class.respond_to?(name)
14
+ Thread.new{
15
+ @class.send name, *args
16
+ }
17
+ else
18
+ @class.send name, *args
19
+ end
20
+ end
21
+ def exit
22
+ @exit = true
23
+ end
24
+ end
metadata ADDED
@@ -0,0 +1,58 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: amirka-async-fu
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Amir Mamedov
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-03-06 00:00:00 -08:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description:
17
+ email: amir@mamedov.eu
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - README.rdoc
24
+ - LICENSE
25
+ files:
26
+ - README.rdoc
27
+ - VERSION.yml
28
+ - lib/async_fu.rb
29
+ - LICENSE
30
+ has_rdoc: true
31
+ homepage: http://github.com/amirka/async-fu
32
+ post_install_message:
33
+ rdoc_options:
34
+ - --inline-source
35
+ - --charset=UTF-8
36
+ require_paths:
37
+ - lib
38
+ required_ruby_version: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: "0"
43
+ version:
44
+ required_rubygems_version: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: "0"
49
+ version:
50
+ requirements: []
51
+
52
+ rubyforge_project:
53
+ rubygems_version: 1.2.0
54
+ signing_key:
55
+ specification_version: 2
56
+ summary: TODO
57
+ test_files: []
58
+