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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d65fa0f57aa1ac91c26b613bca068bd6cc4e2154
4
- data.tar.gz: 12deadde6d42302b9ead771df100fd279ac31d77
3
+ metadata.gz: 01f127618e81e42ba5a0f2e6771231760023fc60
4
+ data.tar.gz: c596488aa8c338ed7d473f30324ab5fa9893c7ac
5
5
  SHA512:
6
- metadata.gz: f08747e36f3f3b1cacc2bdae42c64b10a6b72ccae9ab7c5cfd405ef57f18cdc24599a649b28279b60bef52172560ae90210e53eb9db80a23de667543ce67859d
7
- data.tar.gz: 52b7f4af1e8cb7626d82c194cbeacc1a51732625113161111eff16f876e16b313b9315d7670bac641a8defe5d937b0b1d9e7abbf288686291c5ab3e54febef71
6
+ metadata.gz: e4f66d2d4307e7e1496194a61d2a420138c5b83b37c709e608258ba9791d07f9b71d6d154abdd65dd8902824633f472c2978151c318f4346f0967b8daba87264
7
+ data.tar.gz: 76da0f752e66b969437521d57ccef782c77ad3afc551fca4bce78ae824b6b0a2c0c778d85aef7c50683d41e8de7e41ae819d799bc8d6a5136b1911b857ae9322
@@ -1,64 +1,13 @@
1
1
  require "no_sltd/version"
2
2
 
3
3
  module NoSLTD
4
- CONTINUE = Object.new
5
- THREAD_LOCAL_KEY = :no_sltd_runner
6
-
7
- class Runner
8
- attr_reader :result
9
- def initialize
10
- @fibers = []
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
 
@@ -1,3 +1,3 @@
1
1
  module NoSLTD
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: no_sltd
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - tompng