rbgo 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +11 -1
- data/lib/rbgo/once.rb +28 -0
- data/lib/rbgo/version.rb +1 -1
- data/lib/rbgo.rb +1 -0
- data/rbgo.gemspec +5 -5
- metadata +9 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1f41f240aefabac4cbcd7afbde10dda6bbe8b3a5bc68668f9c7ed5020cc95fe9
|
4
|
+
data.tar.gz: 85301648860872e2322b3817831ab0a100906035030b7d29d5130ac9bb2f23b2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e8d4e07386198c12fd87b95159da9d69ec5127d87d6ad1912266e96b9388931dd25a83b2480e9c1dcc5f068ac73ba44d5ea42212d41ce9e215d4fdfe7145438d
|
7
|
+
data.tar.gz: 5076511a06a460278a37d00da162238c9454b351666349ebedd2d4a9ab8930052c279e22cf8b0fdd99bcf9fc1502b05b66e0200884a90d7c9180119dd87f8e5d
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -42,6 +42,16 @@ select_chan(
|
|
42
42
|
# go
|
43
43
|
create lightweight routine like golang
|
44
44
|
|
45
|
+
Routine does not create a thread instead it is picked by a thread in pool.
|
46
|
+
|
47
|
+
Routine use fiber to yield processor, so you can call Fiber.yield, just like Gosched() in golang.
|
48
|
+
|
49
|
+
If routine raise exception it does not affect other routine. Check Routine#alive? to see if it is alive, and check Routine#error to see if something went wrong.
|
50
|
+
|
51
|
+
If routine is suspended by a blocking operation for enough long time, a new thread will be created to handle other routine. Suspended thread will exit when it completes current routine.
|
52
|
+
|
53
|
+
|
54
|
+
|
45
55
|
example:
|
46
56
|
|
47
57
|
```ruby
|
@@ -77,7 +87,7 @@ puts 'wg.wait done'
|
|
77
87
|
|
78
88
|
open TCP or UDP service
|
79
89
|
|
80
|
-
|
90
|
+
Because service handles network request in async mode, it can handle many requests concurrently. If use some Non-GIL ruby implementations such as TruffleRuby or JRuby, it can utilize all your CPU cores.
|
81
91
|
|
82
92
|
|
83
93
|
```ruby
|
data/lib/rbgo/once.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'thread'
|
2
|
+
|
3
|
+
module Rbgo
|
4
|
+
class Once
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
self.mutex = Mutex.new
|
8
|
+
self.called_flag = false
|
9
|
+
end
|
10
|
+
|
11
|
+
def do(&f)
|
12
|
+
return nil if called_flag
|
13
|
+
mutex.synchronize do
|
14
|
+
unless called_flag
|
15
|
+
begin
|
16
|
+
f.call
|
17
|
+
ensure
|
18
|
+
self.called_flag = true
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
attr_accessor :mutex, :called_flag
|
27
|
+
end
|
28
|
+
end
|
data/lib/rbgo/version.rb
CHANGED
data/lib/rbgo.rb
CHANGED
data/rbgo.gemspec
CHANGED
@@ -8,16 +8,16 @@ Gem::Specification.new do |s|
|
|
8
8
|
s.platform = Gem::Platform::RUBY
|
9
9
|
s.authors = ["Wang Yin"]
|
10
10
|
s.email = ["24588062@qq.com"]
|
11
|
-
s.homepage = "https://github.com/wangyin-git/
|
11
|
+
s.homepage = "https://github.com/wangyin-git/rbgo"
|
12
12
|
s.summary = "Write concurrent program with Ruby in Golang style"
|
13
13
|
s.description = <<-END
|
14
|
-
|
14
|
+
Write concurrent program with Ruby in Golang style.
|
15
15
|
|
16
|
-
|
16
|
+
You can produce a light weight routine easily with a method 'go' and communicate with each routine by channel.
|
17
17
|
|
18
|
-
In MRI
|
18
|
+
In MRI the GIL prevents you from running code parallelly, but there ara also other ruby implementations such as TruffleRuby or JRuby which can utilize all CPU cores.
|
19
19
|
|
20
|
-
|
20
|
+
In MRI write program to run concurrently even not parallelly is also important.
|
21
21
|
END
|
22
22
|
s.add_dependency "sys-cpu", "~> 0.8"
|
23
23
|
s.files = `git ls-files`.split("\n")
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rbgo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Wang Yin
|
@@ -24,13 +24,13 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0.8'
|
27
|
-
description: "
|
28
|
-
|
29
|
-
|
30
|
-
|
27
|
+
description: " Write concurrent program with Ruby in Golang style.
|
28
|
+
\ \n\n You can produce a light weight routine easily with a method
|
29
|
+
'go' and communicate with each routine by channel.\n\n In MRI
|
30
|
+
the GIL prevents you from running code parallelly, but there ara also other ruby
|
31
|
+
implementations such as TruffleRuby or JRuby which can utilize all CPU cores.\n\n
|
31
32
|
\ In MRI write program to run concurrently even not parallelly
|
32
|
-
is also important
|
33
|
-
concurrent program with ruby a little easier.\n"
|
33
|
+
is also important.\n"
|
34
34
|
email:
|
35
35
|
- 24588062@qq.com
|
36
36
|
executables: []
|
@@ -45,11 +45,12 @@ files:
|
|
45
45
|
- lib/rbgo.rb
|
46
46
|
- lib/rbgo/corun.rb
|
47
47
|
- lib/rbgo/network_service.rb
|
48
|
+
- lib/rbgo/once.rb
|
48
49
|
- lib/rbgo/select_chan.rb
|
49
50
|
- lib/rbgo/version.rb
|
50
51
|
- lib/rbgo/wait_group.rb
|
51
52
|
- rbgo.gemspec
|
52
|
-
homepage: https://github.com/wangyin-git/
|
53
|
+
homepage: https://github.com/wangyin-git/rbgo
|
53
54
|
licenses:
|
54
55
|
- MIT
|
55
56
|
metadata: {}
|