pwork 1.2.1 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/pwork/async.rb +34 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 287685ce40b96d3cbb7526a722f5398b5124f7611288bfd641f820fe599b73e8
|
4
|
+
data.tar.gz: 4f06fcec0e7472125c9473409b397f01dceaba18b555b5a8d1c29bb2fa0a6dbc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cd1dd3ca81c5895f3d7c4e8e5d308fe5616740dd127f921db00a6dcdb50e83d9186ef54d632d28228d364b4f5b07484c3935dc7d55ab4943e7fc81137383d0e7
|
7
|
+
data.tar.gz: 0d45e837cb699245c142367a00262b3002adc4484e8161309fe73e280b66a6b8842536ab08aeaa80cc320abad7a35b9eb3047c4a1268140d8bb050dc5fa8ee5e
|
data/lib/pwork/async.rb
CHANGED
@@ -5,6 +5,28 @@ require_relative 'async/manager'
|
|
5
5
|
module PWork
|
6
6
|
module Async
|
7
7
|
def async(options = {}, &block)
|
8
|
+
if PWork::Async.mode == 'fork'
|
9
|
+
PWork::Async.async_forked(options, &block)
|
10
|
+
else
|
11
|
+
PWork::Async.async_threaded(options, &block)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.async_forked(options = {}, &block)
|
16
|
+
if block_given?
|
17
|
+
pid = fork do
|
18
|
+
block.call
|
19
|
+
end
|
20
|
+
PWork::Async.tasks << pid unless options[:wait] == false
|
21
|
+
else
|
22
|
+
PWork::Async.tasks.each do |pid|
|
23
|
+
Process.wait(pid)
|
24
|
+
end
|
25
|
+
reset
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.async_threaded(options = {}, &block)
|
8
30
|
if block_given?
|
9
31
|
options[:caller] = self
|
10
32
|
PWork::Async.add_task(options, &block)
|
@@ -70,5 +92,17 @@ module PWork
|
|
70
92
|
def self.async_wait_sleep_iteration
|
71
93
|
Float(ENV.fetch('PWORK_ASYNC_WAIT_SLEEP_ITERATION', '0.02'))
|
72
94
|
end
|
95
|
+
|
96
|
+
def self.mode
|
97
|
+
if ENV['PWORK_ASYNC_MODE'].to_s.downcase == 'fork'
|
98
|
+
'fork'
|
99
|
+
else
|
100
|
+
'thread'
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
def self.reset
|
105
|
+
Thread.current[:pwork_async_tasks] = []
|
106
|
+
end
|
73
107
|
end
|
74
108
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pwork
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- vaughanbrittonsage
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-02-
|
11
|
+
date: 2018-02-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|