rbgo 0.1.2 → 0.1.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6b7d4112a298f4a00764f1b82c47c1f943f6b83688dd623351d09d7b87acf125
4
- data.tar.gz: ac2778f7c8c479bb7e0ea545e870ca9757ea2836528bb80bd9743c6bc4992f7a
3
+ metadata.gz: 1f41f240aefabac4cbcd7afbde10dda6bbe8b3a5bc68668f9c7ed5020cc95fe9
4
+ data.tar.gz: 85301648860872e2322b3817831ab0a100906035030b7d29d5130ac9bb2f23b2
5
5
  SHA512:
6
- metadata.gz: 8a08a97d29e741ed4133272da25d865d8236f1c5f8f8455c53e80959d41d8c7108ac891ac4598b1b2c8d04d508e7712190b8e26661a5310491ce07335b925037
7
- data.tar.gz: 86d7c76d6ace344c23c7d85b67c2597ef6ce1f967abd9faf4a07067f83a16b7d99edb9ccece5997ebdf0182e46f48a7da00eec07a6fceee65496799660248285
6
+ metadata.gz: e8d4e07386198c12fd87b95159da9d69ec5127d87d6ad1912266e96b9388931dd25a83b2480e9c1dcc5f068ac73ba44d5ea42212d41ce9e215d4fdfe7145438d
7
+ data.tar.gz: 5076511a06a460278a37d00da162238c9454b351666349ebedd2d4a9ab8930052c279e22cf8b0fdd99bcf9fc1502b05b66e0200884a90d7c9180119dd87f8e5d
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rbgo (0.1.1)
4
+ rbgo (0.1.3)
5
5
  sys-cpu (~> 0.8)
6
6
 
7
7
  GEM
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
- 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.
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
@@ -1,3 +1,3 @@
1
1
  module Rbgo
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
data/lib/rbgo.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require_relative 'rbgo/corun'
2
2
  require_relative 'rbgo/select_chan'
3
3
  require_relative 'rbgo/wait_group'
4
+ require_relative 'rbgo/once'
4
5
  require_relative 'rbgo/network_service'
5
6
  require_relative 'rbgo/version'
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/select_chan"
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
- You can produce a light weight routine easily with a keyword 'go' and communicate with each routine by channel.
14
+ Write concurrent program with Ruby in Golang style.
15
15
 
16
- 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.
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 write program to run concurrently even not parallelly is also important.
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
- This project is trying to help writing concurrent program with ruby a little easier.
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.2
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: " You can produce a light weight routine easily with
28
- a keyword 'go' and communicate with each routine by channel.\n\n In
29
- MRI the GIL prevents you from running code parallelly, but there ara also other
30
- ruby implementations such as TruffleRuby or JRuby which can utilize all CPU cores.\n\n
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. \n\n This project is trying to help writing
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/select_chan
53
+ homepage: https://github.com/wangyin-git/rbgo
53
54
  licenses:
54
55
  - MIT
55
56
  metadata: {}