no_sltd 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/no_sltd.rb +7 -58
- data/lib/no_sltd/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 01f127618e81e42ba5a0f2e6771231760023fc60
|
4
|
+
data.tar.gz: c596488aa8c338ed7d473f30324ab5fa9893c7ac
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e4f66d2d4307e7e1496194a61d2a420138c5b83b37c709e608258ba9791d07f9b71d6d154abdd65dd8902824633f472c2978151c318f4346f0967b8daba87264
|
7
|
+
data.tar.gz: 76da0f752e66b969437521d57ccef782c77ad3afc551fca4bce78ae824b6b0a2c0c778d85aef7c50683d41e8de7e41ae819d799bc8d6a5136b1911b857ae9322
|
data/lib/no_sltd.rb
CHANGED
@@ -1,64 +1,13 @@
|
|
1
1
|
require "no_sltd/version"
|
2
2
|
|
3
3
|
module NoSLTD
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
@stack_level = 0
|
12
|
-
end
|
13
|
-
|
14
|
-
def << fiber
|
15
|
-
@fibers << fiber
|
16
|
-
end
|
17
|
-
|
18
|
-
def start &block
|
19
|
-
self << Fiber.new { block.call }
|
20
|
-
until @fibers.empty? do
|
21
|
-
f = @fibers.last
|
22
|
-
next unless f
|
23
|
-
res = f.resume
|
24
|
-
if res != CONTINUE
|
25
|
-
@result = res
|
26
|
-
@fibers.pop
|
27
|
-
end
|
28
|
-
end
|
29
|
-
@result
|
30
|
-
end
|
31
|
-
|
32
|
-
def direct_callable?
|
33
|
-
if @stack_level < 64
|
34
|
-
@stack_level += 1
|
35
|
-
true
|
36
|
-
else
|
37
|
-
@stack_level = 0
|
38
|
-
false
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
def self.execute &block
|
43
|
-
runner = Runner.new
|
44
|
-
Thread.current.thread_variable_set(THREAD_LOCAL_KEY, runner)
|
45
|
-
runner.start(&block)
|
46
|
-
ensure
|
47
|
-
Thread.current.thread_variable_set(THREAD_LOCAL_KEY, nil)
|
48
|
-
end
|
49
|
-
|
50
|
-
def self.current
|
51
|
-
Thread.current.thread_variable_get(THREAD_LOCAL_KEY)
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
def self.recursive &block
|
56
|
-
runner = Runner.current
|
57
|
-
return Runner.execute(&block) unless runner
|
58
|
-
return yield if runner.direct_callable?
|
59
|
-
runner << Fiber.new(&block)
|
60
|
-
Fiber.yield CONTINUE
|
61
|
-
runner.result
|
4
|
+
THREAD_LOCAL_KEY = :no_sltd_stack_level
|
5
|
+
def self.recursive
|
6
|
+
level = (Thread.current[THREAD_LOCAL_KEY] || 0)
|
7
|
+
Thread.current[THREAD_LOCAL_KEY] = level + 1
|
8
|
+
out = level < 64 ? yield : Fiber.new { yield }.resume
|
9
|
+
Thread.current[THREAD_LOCAL_KEY] = level
|
10
|
+
out
|
62
11
|
end
|
63
12
|
end
|
64
13
|
|
data/lib/no_sltd/version.rb
CHANGED