deadline_machines 0.1.3 → 0.2.0
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 +4 -4
- data/CHANGELOG.md +11 -0
- data/Cargo.lock +371 -0
- data/Cargo.toml +12 -1
- data/README.md +52 -25
- data/ext/deadline_machines_native/core/CHANGELOG.md +44 -0
- data/ext/deadline_machines_native/core/Cargo.toml +10 -7
- data/ext/deadline_machines_native/core/README.md +105 -0
- data/ext/deadline_machines_native/core/src/cancel.rs +175 -0
- data/ext/deadline_machines_native/core/src/deadline.rs +141 -0
- data/ext/deadline_machines_native/core/src/lib.rs +19 -631
- data/ext/deadline_machines_native/core/src/refusal.rs +28 -0
- data/ext/deadline_machines_native/core/src/scope.rs +147 -0
- data/ext/deadline_machines_native/core/src/tokio_support.rs +107 -0
- data/ext/deadline_machines_native/extconf.rb +2 -0
- data/ext/deadline_machines_native/ffi/Cargo.toml +23 -0
- data/ext/deadline_machines_native/ffi/extconf.rb +14 -0
- data/ext/deadline_machines_native/ffi/src/init.rs +31 -0
- data/ext/deadline_machines_native/ffi/src/lib.rs +146 -0
- data/lib/deadline_machines/cancel_token.rb +152 -0
- data/lib/deadline_machines/clock.rb +22 -5
- data/lib/deadline_machines/errors.rb +10 -6
- data/lib/deadline_machines/scope.rb +152 -0
- data/lib/deadline_machines/version.rb +1 -1
- data/lib/deadline_machines.rb +70 -16
- data/sig/deadline_machines.rbs +116 -35
- metadata +46 -8
- data/lib/deadline_machines/deadline.rb +0 -183
|
@@ -1,22 +1,26 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
module DeadlineMachines
|
|
4
|
+
# What a checkpoint raises. Refusals as values are the symbols of
|
|
5
|
+
# {REFUSALS}; these exist so `check!` can unwind cooperative work.
|
|
4
6
|
class Error < StandardError; end
|
|
5
7
|
|
|
8
|
+
# The budget of +scope+ ran out.
|
|
6
9
|
class Exceeded < Error
|
|
7
|
-
attr_reader :
|
|
10
|
+
attr_reader :scope
|
|
8
11
|
|
|
9
|
-
def initialize(
|
|
10
|
-
@
|
|
12
|
+
def initialize(scope)
|
|
13
|
+
@scope = scope
|
|
11
14
|
super('deadline exceeded')
|
|
12
15
|
end
|
|
13
16
|
end
|
|
14
17
|
|
|
18
|
+
# +scope+ or an ancestor was cancelled, for +reason+.
|
|
15
19
|
class Cancelled < Error
|
|
16
|
-
attr_reader :
|
|
20
|
+
attr_reader :scope, :reason
|
|
17
21
|
|
|
18
|
-
def initialize(
|
|
19
|
-
@
|
|
22
|
+
def initialize(scope, reason = nil)
|
|
23
|
+
@scope = scope
|
|
20
24
|
@reason = reason
|
|
21
25
|
super(reason ? "deadline cancelled: #{reason}" : 'deadline cancelled')
|
|
22
26
|
end
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module DeadlineMachines
|
|
4
|
+
# A {Deadline} and a {CancelToken} as one value, the runtime peer of the
|
|
5
|
+
# core's `Scope`. Where the core takes `now`, a scope reads its clock
|
|
6
|
+
# (`clock` keyword, {DeadlineMachines.clock} by default): that clock and
|
|
7
|
+
# the token's Ruby observers are what this runtime adds on top of the core.
|
|
8
|
+
# Frozen; scopes sharing a token share cancellation.
|
|
9
|
+
class Scope
|
|
10
|
+
attr_reader :deadline, :token, :clock
|
|
11
|
+
|
|
12
|
+
class << self
|
|
13
|
+
# A scope under +deadline+ with a fresh root token.
|
|
14
|
+
def new(deadline, clock: DeadlineMachines.clock)
|
|
15
|
+
with_token(deadline, CancelToken.root, clock: clock)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
# A scope with no time limit, cancellable only.
|
|
19
|
+
def never(clock: DeadlineMachines.clock)
|
|
20
|
+
new(Deadline.never, clock: clock)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
# A scope under +deadline+ that shares +token+. The deadline is read
|
|
24
|
+
# natively, as every Deadline operation reads one, and the scope keeps
|
|
25
|
+
# the value rebuilt from it. The token and the clock are this runtime's
|
|
26
|
+
# own Ruby objects and are checked here.
|
|
27
|
+
def with_token(deadline, token, clock: DeadlineMachines.clock)
|
|
28
|
+
deadline = DeadlineMachines.__send__(:__deadline_of, deadline)
|
|
29
|
+
raise TypeError, 'token must be a DeadlineMachines::CancelToken' unless token.instance_of?(CancelToken)
|
|
30
|
+
raise TypeError, 'clock must respond to now_ns' unless clock.respond_to?(:now_ns)
|
|
31
|
+
|
|
32
|
+
scope = allocate
|
|
33
|
+
scope.__send__(:initialize, deadline, token, clock)
|
|
34
|
+
scope
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def initialize(deadline, token, clock)
|
|
39
|
+
@deadline = deadline
|
|
40
|
+
@token = token
|
|
41
|
+
@clock = clock
|
|
42
|
+
freeze
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
# Nanoseconds left, zero once spent, nil when there is no limit.
|
|
46
|
+
def remaining
|
|
47
|
+
@deadline.remaining(now)
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def expired?
|
|
51
|
+
@deadline.expired?(now)
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def cancelled?
|
|
55
|
+
@token.cancelled?
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def done?
|
|
59
|
+
cancelled? || expired?
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
# Why this scope or the nearest cancelled ancestor was cancelled.
|
|
63
|
+
def reason
|
|
64
|
+
@token.reason
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
# The checkpoint as a value: nil, or the refusal symbol. :cancelled
|
|
68
|
+
# outranks :exceeded.
|
|
69
|
+
def check
|
|
70
|
+
return :cancelled if cancelled?
|
|
71
|
+
|
|
72
|
+
@deadline.check(now)
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
# The cooperative checkpoint: raises Cancelled (which outranks) or
|
|
76
|
+
# Exceeded, else returns self.
|
|
77
|
+
def check!
|
|
78
|
+
raise Cancelled.new(self, reason) if cancelled?
|
|
79
|
+
raise Exceeded, self if expired?
|
|
80
|
+
|
|
81
|
+
self
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
# The longest sleep up to +requested+ nanoseconds that still fits.
|
|
85
|
+
def clamp_sleep(requested)
|
|
86
|
+
@deadline.clamp_sleep(now, requested)
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
# See {CancelToken#cancel}: :propagated or :already_cancelled.
|
|
90
|
+
def cancel(reason = nil)
|
|
91
|
+
@token.cancel(reason)
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
# Calls the block with this scope once it is cancelled, at once if it
|
|
95
|
+
# already is.
|
|
96
|
+
def on_cancel
|
|
97
|
+
@token.on_cancel { yield self }
|
|
98
|
+
self
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
# A child scope whose deadline is the tighter of this one and +timeout+
|
|
102
|
+
# nanoseconds from now, cancellable on its own. With a block, the child
|
|
103
|
+
# is yielded and unlinked when the block exits; the block's value is
|
|
104
|
+
# returned.
|
|
105
|
+
def derive(timeout, &)
|
|
106
|
+
below(@deadline.derive(now, timeout), &)
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
# A child scope with the same deadline, cancellable on its own; the block
|
|
110
|
+
# form as {#derive}.
|
|
111
|
+
def child(&)
|
|
112
|
+
below(@deadline, &)
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
# This scope with the tighter of its deadline and +other+, sharing its
|
|
116
|
+
# cancellation.
|
|
117
|
+
def tighten(other)
|
|
118
|
+
Scope.with_token(@deadline.tighten(other), @token, clock: @clock)
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
# This scope with its expiry pushed back by +by+ nanoseconds, sharing its
|
|
122
|
+
# cancellation.
|
|
123
|
+
def extend_by(by)
|
|
124
|
+
Scope.with_token(@deadline.extend_by(by), @token, clock: @clock)
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
def inspect
|
|
128
|
+
"#<#{self.class} #{state}>"
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
private
|
|
132
|
+
|
|
133
|
+
def now
|
|
134
|
+
@clock.now_ns
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
def below(deadline)
|
|
138
|
+
return Scope.with_token(deadline, @token.child, clock: @clock) unless block_given?
|
|
139
|
+
|
|
140
|
+
@token.child { |token| yield Scope.with_token(deadline, token, clock: @clock) }
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
def state
|
|
144
|
+
return 'cancelled' if cancelled?
|
|
145
|
+
|
|
146
|
+
left = remaining
|
|
147
|
+
return 'unbounded' if left.nil?
|
|
148
|
+
|
|
149
|
+
left.zero? ? 'expired' : "#{left}ns left"
|
|
150
|
+
end
|
|
151
|
+
end
|
|
152
|
+
end
|
data/lib/deadline_machines.rb
CHANGED
|
@@ -1,56 +1,110 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require_relative 'deadline_machines/version'
|
|
4
|
+
|
|
5
|
+
# Every instant and span in this gem is Integer nanoseconds: `now` as read
|
|
6
|
+
# from `Process.clock_gettime(Process::CLOCK_MONOTONIC, :nanosecond)`, and
|
|
7
|
+
# every timeout, extension, remaining budget and sleep. They reach the core
|
|
8
|
+
# as a `Duration`, so each is in 0..Duration::MAX nanoseconds; TypeError for
|
|
9
|
+
# anything but an Integer, RangeError outside that range.
|
|
10
|
+
module DeadlineMachines
|
|
11
|
+
# When a budget runs out: `expires_at` is an instant in Integer
|
|
12
|
+
# nanoseconds, or nil for never. A frozen value, validated through the core
|
|
13
|
+
# whether the gem built it or the caller did. `never`, `at`, `after` and
|
|
14
|
+
# every operation below are native and mirror the core's `Deadline`;
|
|
15
|
+
# `extend_by` is the core's `extend`, renamed so it does not shadow
|
|
16
|
+
# `Object#extend`.
|
|
17
|
+
Deadline = Data.define(:expires_at) do
|
|
18
|
+
def initialize(expires_at:)
|
|
19
|
+
DeadlineMachines.__send__(:__deadline, expires_at)
|
|
20
|
+
super
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
# Native is required: no algorithm fallback. It validates and builds the
|
|
26
|
+
# Deadline above and adds its arithmetic, so the class must exist first.
|
|
27
|
+
require 'deadline_machines_native/deadline_machines_native'
|
|
28
|
+
|
|
29
|
+
module DeadlineMachines
|
|
30
|
+
private_class_method :__deadline, :__deadline_of
|
|
31
|
+
|
|
32
|
+
# The value is sealed. `initialize` is where it validates, and a subclass
|
|
33
|
+
# could override it, or `allocate` build an instance that never ran it:
|
|
34
|
+
# subclassing raises TypeError and `allocate` is gone. Sealing stops
|
|
35
|
+
# accidents, not reflection (`Marshal.load` skips `initialize`), so the
|
|
36
|
+
# native side is the authority: a Deadline it reads must be exactly that
|
|
37
|
+
# class, and its expiry is checked again.
|
|
38
|
+
Deadline.singleton_class.undef_method(:allocate)
|
|
39
|
+
Deadline.define_singleton_method(:inherited) { |_| raise TypeError, "#{Deadline} cannot be subclassed" }
|
|
40
|
+
end
|
|
41
|
+
|
|
4
42
|
require_relative 'deadline_machines/errors'
|
|
5
43
|
require_relative 'deadline_machines/clock'
|
|
6
|
-
require_relative 'deadline_machines/
|
|
44
|
+
require_relative 'deadline_machines/cancel_token'
|
|
45
|
+
require_relative 'deadline_machines/scope'
|
|
7
46
|
|
|
47
|
+
# The ambient scope: a runtime layered on the core, bound per fiber.
|
|
8
48
|
module DeadlineMachines
|
|
9
|
-
FIBER_KEY = :
|
|
49
|
+
FIBER_KEY = :deadline_machines_scope
|
|
10
50
|
|
|
11
51
|
class << self
|
|
12
52
|
attr_writer :clock
|
|
13
53
|
|
|
54
|
+
# What every scope built without an explicit clock reads.
|
|
14
55
|
def clock
|
|
15
56
|
@clock ||= MonotonicClock
|
|
16
57
|
end
|
|
17
58
|
|
|
59
|
+
# The scope bound to this fiber, or nil.
|
|
18
60
|
def current
|
|
19
61
|
Fiber[FIBER_KEY]
|
|
20
62
|
end
|
|
21
63
|
|
|
22
|
-
|
|
64
|
+
# Runs the block under a scope bound to this fiber, and returns its value.
|
|
65
|
+
# Under an ambient scope it is a child of that one, tightened to
|
|
66
|
+
# +timeout+ nanoseconds when given; otherwise a root scope that runs out
|
|
67
|
+
# +timeout+ nanoseconds from now, or never.
|
|
68
|
+
def with_deadline(timeout = nil, &)
|
|
23
69
|
ambient = current
|
|
24
|
-
|
|
25
|
-
|
|
70
|
+
if ambient
|
|
71
|
+
return ambient.child { |scope| bind(scope, &) } if timeout.nil?
|
|
26
72
|
|
|
27
|
-
|
|
73
|
+
return ambient.derive(timeout) { |scope| bind(scope, &) }
|
|
74
|
+
end
|
|
75
|
+
deadline = timeout.nil? ? Deadline.never : Deadline.after(clock.now_ns, timeout)
|
|
76
|
+
bind(Scope.new(deadline), &)
|
|
28
77
|
end
|
|
29
78
|
|
|
30
|
-
|
|
79
|
+
# Binds +scope+ to this fiber for the block, restoring the previous one.
|
|
80
|
+
def bind(scope)
|
|
81
|
+
raise TypeError, 'scope must be a DeadlineMachines::Scope' unless scope.instance_of?(Scope)
|
|
82
|
+
|
|
31
83
|
previous = Fiber[FIBER_KEY]
|
|
32
|
-
Fiber[FIBER_KEY] =
|
|
84
|
+
Fiber[FIBER_KEY] = scope
|
|
33
85
|
begin
|
|
34
|
-
yield
|
|
86
|
+
yield scope
|
|
35
87
|
ensure
|
|
36
88
|
Fiber[FIBER_KEY] = previous
|
|
37
89
|
end
|
|
38
90
|
end
|
|
39
91
|
|
|
92
|
+
# The ambient checkpoint: raises Cancelled or Exceeded, else returns the
|
|
93
|
+
# scope, or nil outside one.
|
|
40
94
|
def check!
|
|
41
95
|
current&.check!
|
|
42
96
|
end
|
|
43
97
|
|
|
98
|
+
# Nanoseconds left in the ambient scope, nil when there is no limit.
|
|
44
99
|
def remaining
|
|
45
|
-
current&.remaining
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
def clamp_sleep(seconds)
|
|
49
|
-
current ? current.clamp_sleep(seconds) : seconds
|
|
100
|
+
current&.remaining
|
|
50
101
|
end
|
|
51
102
|
|
|
52
|
-
|
|
53
|
-
|
|
103
|
+
# The longest sleep up to +requested+ nanoseconds that fits the ambient
|
|
104
|
+
# budget; +requested+ itself outside a scope.
|
|
105
|
+
def clamp_sleep(requested)
|
|
106
|
+
scope = current
|
|
107
|
+
scope ? scope.clamp_sleep(requested) : Deadline.never.clamp_sleep(0, requested)
|
|
54
108
|
end
|
|
55
109
|
end
|
|
56
110
|
end
|
data/sig/deadline_machines.rbs
CHANGED
|
@@ -2,23 +2,57 @@ module DeadlineMachines
|
|
|
2
2
|
VERSION: String
|
|
3
3
|
FIBER_KEY: Symbol
|
|
4
4
|
|
|
5
|
-
#
|
|
5
|
+
# :exceeded, :cancelled: the core's Refusal, in declaration order.
|
|
6
|
+
REFUSALS: Array[refusal]
|
|
7
|
+
|
|
8
|
+
type refusal = :exceeded | :cancelled
|
|
9
|
+
type cancellation = :propagated | :already_cancelled
|
|
10
|
+
|
|
11
|
+
# Any monotonic clock in Integer nanoseconds.
|
|
6
12
|
interface _Clock
|
|
7
13
|
def now_ns: () -> Integer
|
|
8
14
|
end
|
|
9
15
|
|
|
16
|
+
# When a budget runs out, Integer nanoseconds or nil for never. Native and
|
|
17
|
+
# validated through the core.
|
|
18
|
+
class Deadline < Data
|
|
19
|
+
attr_reader expires_at: Integer?
|
|
20
|
+
|
|
21
|
+
def self.new: (Integer? expires_at) -> Deadline
|
|
22
|
+
| (expires_at: Integer?) -> Deadline
|
|
23
|
+
def self.[]: (Integer? expires_at) -> Deadline
|
|
24
|
+
| (expires_at: Integer?) -> Deadline
|
|
25
|
+
def self.members: () -> [:expires_at]
|
|
26
|
+
|
|
27
|
+
def self.never: () -> Deadline
|
|
28
|
+
def self.at: (Integer instant) -> Deadline
|
|
29
|
+
def self.after: (Integer now, Integer timeout) -> Deadline
|
|
30
|
+
|
|
31
|
+
def initialize: (expires_at: Integer?) -> void
|
|
32
|
+
|
|
33
|
+
# nil when there is no limit.
|
|
34
|
+
def remaining: (Integer now) -> Integer?
|
|
35
|
+
def expired?: (Integer now) -> bool
|
|
36
|
+
# nil while live, :exceeded at or past expires_at.
|
|
37
|
+
def check: (Integer now) -> (:exceeded | nil)
|
|
38
|
+
def derive: (Integer now, Integer timeout) -> Deadline
|
|
39
|
+
def extend_by: (Integer by) -> Deadline
|
|
40
|
+
def tighten: (Deadline other) -> Deadline
|
|
41
|
+
def clamp_sleep: (Integer now, Integer requested) -> Integer
|
|
42
|
+
end
|
|
43
|
+
|
|
10
44
|
class Error < StandardError
|
|
11
45
|
end
|
|
12
46
|
|
|
13
47
|
class Exceeded < Error
|
|
14
|
-
attr_reader
|
|
15
|
-
def initialize: (
|
|
48
|
+
attr_reader scope: Scope
|
|
49
|
+
def initialize: (Scope scope) -> void
|
|
16
50
|
end
|
|
17
51
|
|
|
18
52
|
class Cancelled < Error
|
|
19
|
-
attr_reader
|
|
53
|
+
attr_reader scope: Scope
|
|
20
54
|
attr_reader reason: untyped
|
|
21
|
-
def initialize: (
|
|
55
|
+
def initialize: (Scope scope, ?untyped reason) -> void
|
|
22
56
|
end
|
|
23
57
|
|
|
24
58
|
module MonotonicClock
|
|
@@ -26,53 +60,100 @@ module DeadlineMachines
|
|
|
26
60
|
end
|
|
27
61
|
|
|
28
62
|
class TestClock
|
|
29
|
-
|
|
30
|
-
def initialize: (?now_ns
|
|
31
|
-
def
|
|
63
|
+
attr_reader now_ns: Integer
|
|
64
|
+
def initialize: (?Integer now_ns) -> void
|
|
65
|
+
def now_ns=: (Integer now_ns) -> Integer
|
|
66
|
+
def advance: (Integer nanos) -> self
|
|
67
|
+
|
|
68
|
+
private
|
|
69
|
+
|
|
70
|
+
def nanoseconds: (Integer value) -> Integer
|
|
32
71
|
end
|
|
33
72
|
|
|
34
|
-
|
|
35
|
-
|
|
73
|
+
# The runtime cancellation tree.
|
|
74
|
+
class CancelToken
|
|
75
|
+
def self.root: () -> CancelToken
|
|
76
|
+
|
|
77
|
+
def initialize: (CancelToken? parent) -> void
|
|
78
|
+
def cancelled?: () -> bool
|
|
79
|
+
def reason: () -> untyped
|
|
80
|
+
def cancel: (?untyped reason) -> cancellation
|
|
81
|
+
def on_cancel: () { (CancelToken) -> void } -> self
|
|
82
|
+
|
|
83
|
+
# Without a block the child is returned; with one it is unlinked on exit
|
|
84
|
+
# and the block's value is returned.
|
|
85
|
+
def child: () -> CancelToken
|
|
86
|
+
| [T] () { (CancelToken) -> T } -> T
|
|
87
|
+
|
|
88
|
+
def inspect: () -> String
|
|
89
|
+
|
|
90
|
+
private def self.new: (CancelToken? parent) -> CancelToken
|
|
91
|
+
|
|
92
|
+
attr_reader mutex: Thread::Mutex
|
|
93
|
+
attr_writer detached: bool
|
|
94
|
+
|
|
95
|
+
def propagate: (untyped reason, bool inherited) -> bool
|
|
96
|
+
def hold: (CancelToken token) -> void
|
|
97
|
+
def drop: (CancelToken token) -> void
|
|
98
|
+
def detach: (CancelToken token) -> void
|
|
99
|
+
def pending?: () -> bool
|
|
100
|
+
|
|
101
|
+
private
|
|
36
102
|
|
|
37
|
-
|
|
38
|
-
|
|
103
|
+
def notify: (Array[StandardError] failures) { () -> void } -> void
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
# A Deadline read against a clock, and a CancelToken.
|
|
107
|
+
class Scope
|
|
108
|
+
attr_reader deadline: Deadline
|
|
109
|
+
attr_reader token: CancelToken
|
|
39
110
|
attr_reader clock: _Clock
|
|
40
|
-
attr_reader reason: untyped
|
|
41
111
|
|
|
42
|
-
def self.
|
|
43
|
-
def self.never: (?clock: _Clock) ->
|
|
44
|
-
def self.
|
|
112
|
+
def self.new: (Deadline deadline, ?clock: _Clock) -> Scope
|
|
113
|
+
def self.never: (?clock: _Clock) -> Scope
|
|
114
|
+
def self.with_token: (Deadline deadline, CancelToken token, ?clock: _Clock) -> Scope
|
|
45
115
|
|
|
46
|
-
def initialize: (
|
|
116
|
+
def initialize: (Deadline deadline, CancelToken token, _Clock clock) -> void
|
|
47
117
|
|
|
48
|
-
# nil when there is no
|
|
49
|
-
def
|
|
50
|
-
def remaining: () -> Float
|
|
118
|
+
# nil when there is no limit.
|
|
119
|
+
def remaining: () -> Integer?
|
|
51
120
|
def expired?: () -> bool
|
|
52
121
|
def cancelled?: () -> bool
|
|
53
122
|
def done?: () -> bool
|
|
123
|
+
def reason: () -> untyped
|
|
124
|
+
def check: () -> refusal?
|
|
54
125
|
def check!: () -> self
|
|
55
|
-
def clamp_sleep: (
|
|
56
|
-
def cancel: (?untyped) ->
|
|
57
|
-
def on_cancel: () { (
|
|
126
|
+
def clamp_sleep: (Integer requested) -> Integer
|
|
127
|
+
def cancel: (?untyped reason) -> cancellation
|
|
128
|
+
def on_cancel: () { (Scope) -> void } -> self
|
|
58
129
|
|
|
59
130
|
# Without a block the child is returned; with one it is unlinked on exit
|
|
60
131
|
# and the block's value is returned.
|
|
61
|
-
def derive: (
|
|
62
|
-
| [T] (
|
|
63
|
-
|
|
132
|
+
def derive: (Integer timeout) -> Scope
|
|
133
|
+
| [T] (Integer timeout) { (Scope) -> T } -> T
|
|
134
|
+
def child: () -> Scope
|
|
135
|
+
| [T] () { (Scope) -> T } -> T
|
|
136
|
+
def tighten: (Deadline other) -> Scope
|
|
137
|
+
def extend_by: (Integer by) -> Scope
|
|
64
138
|
def inspect: () -> String
|
|
65
139
|
|
|
66
|
-
private
|
|
140
|
+
private
|
|
141
|
+
|
|
142
|
+
def now: () -> Integer
|
|
143
|
+
def below: (Deadline deadline) -> Scope
|
|
144
|
+
| [T] (Deadline deadline) { (Scope) -> T } -> T
|
|
145
|
+
def state: () -> String
|
|
67
146
|
end
|
|
68
147
|
|
|
69
148
|
def self.clock: () -> _Clock
|
|
70
|
-
def self.clock=: (_Clock?) -> _Clock?
|
|
71
|
-
def self.current: () ->
|
|
72
|
-
def self.with_deadline: [T] (?
|
|
73
|
-
def self.bind: [T] (
|
|
74
|
-
def self.check!: () ->
|
|
75
|
-
def self.remaining: () ->
|
|
76
|
-
def self.clamp_sleep: (
|
|
77
|
-
|
|
149
|
+
def self.clock=: (_Clock? clock) -> _Clock?
|
|
150
|
+
def self.current: () -> Scope?
|
|
151
|
+
def self.with_deadline: [T] (?Integer? timeout) { (Scope) -> T } -> T
|
|
152
|
+
def self.bind: [T] (Scope scope) { (Scope) -> T } -> T
|
|
153
|
+
def self.check!: () -> Scope?
|
|
154
|
+
def self.remaining: () -> Integer?
|
|
155
|
+
def self.clamp_sleep: (Integer requested) -> Integer
|
|
156
|
+
|
|
157
|
+
private def self.__deadline: (untyped expires_at) -> nil
|
|
158
|
+
private def self.__deadline_of: (untyped deadline) -> Deadline
|
|
78
159
|
end
|
metadata
CHANGED
|
@@ -1,34 +1,70 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: deadline_machines
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Abdelkader Boudih
|
|
8
8
|
bindir: bin
|
|
9
9
|
cert_chain: []
|
|
10
10
|
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
|
-
dependencies:
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
11
|
+
dependencies:
|
|
12
|
+
- !ruby/object:Gem::Dependency
|
|
13
|
+
name: rb_sys
|
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
|
15
|
+
requirements:
|
|
16
|
+
- - "~>"
|
|
17
|
+
- !ruby/object:Gem::Version
|
|
18
|
+
version: '0.9'
|
|
19
|
+
- - ">="
|
|
20
|
+
- !ruby/object:Gem::Version
|
|
21
|
+
version: 0.9.130
|
|
22
|
+
type: :runtime
|
|
23
|
+
prerelease: false
|
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
25
|
+
requirements:
|
|
26
|
+
- - "~>"
|
|
27
|
+
- !ruby/object:Gem::Version
|
|
28
|
+
version: '0.9'
|
|
29
|
+
- - ">="
|
|
30
|
+
- !ruby/object:Gem::Version
|
|
31
|
+
version: 0.9.130
|
|
32
|
+
description: 'A monotonic deadline that derives child budgets, cancels down its tree,
|
|
33
|
+
and raises only at checkpoints you choose. The arithmetic comes from the no_std
|
|
34
|
+
deadline-machines crate; Ruby owns the cancellation tree and the ambient scope.
|
|
35
|
+
The shared time contract for the machines family: retries, circuit breakers and
|
|
36
|
+
throttles read one budget.'
|
|
16
37
|
email:
|
|
17
38
|
- oss@seuros.com
|
|
18
39
|
executables: []
|
|
19
|
-
extensions:
|
|
40
|
+
extensions:
|
|
41
|
+
- ext/deadline_machines_native/extconf.rb
|
|
20
42
|
extra_rdoc_files: []
|
|
21
43
|
files:
|
|
22
44
|
- CHANGELOG.md
|
|
45
|
+
- Cargo.lock
|
|
23
46
|
- Cargo.toml
|
|
24
47
|
- LICENSE.txt
|
|
25
48
|
- README.md
|
|
49
|
+
- ext/deadline_machines_native/core/CHANGELOG.md
|
|
26
50
|
- ext/deadline_machines_native/core/Cargo.toml
|
|
51
|
+
- ext/deadline_machines_native/core/README.md
|
|
52
|
+
- ext/deadline_machines_native/core/src/cancel.rs
|
|
53
|
+
- ext/deadline_machines_native/core/src/deadline.rs
|
|
27
54
|
- ext/deadline_machines_native/core/src/lib.rs
|
|
55
|
+
- ext/deadline_machines_native/core/src/refusal.rs
|
|
56
|
+
- ext/deadline_machines_native/core/src/scope.rs
|
|
57
|
+
- ext/deadline_machines_native/core/src/tokio_support.rs
|
|
58
|
+
- ext/deadline_machines_native/extconf.rb
|
|
59
|
+
- ext/deadline_machines_native/ffi/Cargo.toml
|
|
60
|
+
- ext/deadline_machines_native/ffi/extconf.rb
|
|
61
|
+
- ext/deadline_machines_native/ffi/src/init.rs
|
|
62
|
+
- ext/deadline_machines_native/ffi/src/lib.rs
|
|
28
63
|
- lib/deadline_machines.rb
|
|
64
|
+
- lib/deadline_machines/cancel_token.rb
|
|
29
65
|
- lib/deadline_machines/clock.rb
|
|
30
|
-
- lib/deadline_machines/deadline.rb
|
|
31
66
|
- lib/deadline_machines/errors.rb
|
|
67
|
+
- lib/deadline_machines/scope.rb
|
|
32
68
|
- lib/deadline_machines/version.rb
|
|
33
69
|
- sig/deadline_machines.rbs
|
|
34
70
|
homepage: https://github.com/seuros/deadline_machines
|
|
@@ -39,6 +75,8 @@ metadata:
|
|
|
39
75
|
changelog_uri: https://github.com/seuros/deadline_machines/blob/main/CHANGELOG.md
|
|
40
76
|
bug_tracker_uri: https://github.com/seuros/deadline_machines/issues
|
|
41
77
|
rubygems_mfa_required: 'true'
|
|
78
|
+
cargo_crate_name: deadline_machines_native
|
|
79
|
+
cargo_manifest_path: ext/deadline_machines_native/ffi/Cargo.toml
|
|
42
80
|
rdoc_options: []
|
|
43
81
|
require_paths:
|
|
44
82
|
- lib
|