core-async 0.2.1 → 0.6.1

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: 1361dd8d8fafb99718c6891dc52ec337871557417c924599dbb06eba31bf98bf
4
- data.tar.gz: 863a6748e6af4b6d1e79eb73c7e2fb91305a020694262824080de059a4f3b761
3
+ metadata.gz: ff90fa7ad80389d797bf7890df85843e32a6312eabee3ba15e62ff29eafe8d68
4
+ data.tar.gz: 60d9229247f2a98fb08eea3961019bb2304dff3d9bb056676647923ea21628af
5
5
  SHA512:
6
- metadata.gz: e4c7aba95f41c4da1d44c6f395b7c7c849d0162796b43a7a98aa99550edde255f4f0f09e5d22a1230886c2adf63c54deed36e5987a2d2c3776a6bc9624d310b7
7
- data.tar.gz: 30a459f1b57bb2dd135bd7417df2775364375f76c5065b91722e23b2c2a94906d0dd3605412aa685b75825b847338860d63016ef1c0a0136e7bd5382b072228a
6
+ metadata.gz: f4fddf435f4246ef8094317f658064e8e45e6ca8a30257b0bb4b9afea1658d429b0d87daf5a142a695228c1f85c61c5de33a3c0d3414edfa15b1a4504da79ebc
7
+ data.tar.gz: b888a83b7fba674b0a1e3555295f1052d7044770df9f52bb06f9840160b5f65acfa0383f48bbe045349a950a8624ee4e85f0511c5ed62a7ab60b3dd815d59860
data/CHANGELOG.md CHANGED
@@ -1,3 +1,37 @@
1
+ ## [v0.6.1](https://github.com/metabahn/corerb/releases/tag/2021-05-20.1)
2
+
3
+ *released on 2021-05-20*
4
+
5
+ * `fix` [#29](https://github.com/metabahn/corerb/pull/29) Actually disable the console logger ([bryanp](https://github.com/bryanp))
6
+
7
+ ## [v0.6.0](https://github.com/metabahn/corerb/releases/tag/2021-05-20)
8
+
9
+ *released on 2021-05-20*
10
+
11
+ * `fix` [#28](https://github.com/metabahn/corerb/pull/28) Turn off the console logger in all contexts ([bryanp](https://github.com/bryanp))
12
+ * `chg` [#27](https://github.com/metabahn/corerb/pull/27) Propagate throws from async contexts ([bryanp](https://github.com/bryanp))
13
+
14
+ ## [v0.5.0](https://github.com/metabahn/corerb/releases/tag/2021-03-26)
15
+
16
+ *released on 2021-03-26*
17
+
18
+ * `chg` [#25](https://github.com/metabahn/corerb/pull/25) Privatize async behavior ([bryanp](https://github.com/bryanp))
19
+ * `add` [#24](https://github.com/metabahn/corerb/pull/24) Add Is::Async#cancel ([bryanp](https://github.com/bryanp))
20
+ * `fix` [#23](https://github.com/metabahn/corerb/pull/23) Improve control flow during async enumeration / collection building ([bryanp](https://github.com/bryanp))
21
+ * `fix` [#22](https://github.com/metabahn/corerb/pull/22) Expose errors that occur when building a collection ([bryanp](https://github.com/bryanp))
22
+
23
+ ## [v0.4.0](https://github.com/metabahn/corerb/releases/tag/2021-03-17.1)
24
+
25
+ *released on 2021-03-17*
26
+
27
+ * `chg` [#21](https://github.com/metabahn/corerb/pull/21) Cancel async futures without waiting ([bryanp](https://github.com/bryanp))
28
+
29
+ ## [v0.3.0](https://github.com/metabahn/corerb/releases/tag/2021-03-17)
30
+
31
+ *released on 2021-03-17*
32
+
33
+ * `add` [#20](https://github.com/metabahn/corerb/pull/20) Allow futures to be canceled ([bryanp](https://github.com/bryanp))
34
+
1
35
  ## [v0.2.1](https://github.com/metabahn/corerb/releases/tag/2021-03-05)
2
36
 
3
37
  *released on 2021-03-05*
@@ -1,4 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "async"
4
- Console.logger.off!
4
+
5
+ # Turn the console logger off everywhere.
6
+ #
7
+ ENV["CONSOLE_LEVEL"] ||= "5"
@@ -12,17 +12,26 @@ module Core
12
12
  #
13
13
  def build(object)
14
14
  aware do
15
+ errored, stopped = false
16
+
15
17
  values = object.map { |value|
18
+ break if errored || stopped
19
+
16
20
  async do
17
21
  if block_given?
18
22
  yield value
19
23
  else
20
24
  value
21
25
  end
26
+ rescue LocalJumpError
27
+ stopped = true
28
+ rescue => error
29
+ errored = true
30
+ raise error
22
31
  end
23
32
  }
24
33
 
25
- new(values)
34
+ new(values) if values
26
35
  end
27
36
  end
28
37
  end
@@ -24,20 +24,19 @@ module Core
24
24
  end
25
25
 
26
26
  await do
27
- errored = false
27
+ errored, stopped = false
28
+
28
29
  @object.each do |value|
29
- break if errored
30
-
31
- async {
32
- begin
33
- yield value
34
- rescue => error
35
- errored = true
36
- raise error
37
- ensure
38
- defer
39
- end
40
- }
30
+ break if errored || stopped
31
+
32
+ async do
33
+ yield value
34
+ rescue LocalJumpError
35
+ stopped = true
36
+ rescue => error
37
+ errored = true
38
+ raise error
39
+ end
41
40
  end
42
41
  end
43
42
  end
@@ -10,7 +10,7 @@ module Core
10
10
  @error = nil
11
11
  end
12
12
 
13
- # [public] Wait on the task to complete, returning self.
13
+ # [public] Wait on the future to resolve, returning self.
14
14
  #
15
15
  def wait
16
16
  unless @error
@@ -20,6 +20,16 @@ module Core
20
20
  self
21
21
  end
22
22
 
23
+ # [public] Attempt to cancel the future, returns true if successful.
24
+ #
25
+ def cancel
26
+ if pending?
27
+ @task.stop
28
+ end
29
+
30
+ self
31
+ end
32
+
23
33
  # [public] Return the result, blocking until available.
24
34
  #
25
35
  def result
@@ -30,6 +40,8 @@ module Core
30
40
  wait_all(@task)
31
41
 
32
42
  resolve_value(@task.result)
43
+ rescue UncaughtThrowError => error
44
+ throw error.tag, error.value
33
45
  rescue => error
34
46
  @error = error
35
47
 
@@ -68,6 +80,8 @@ module Core
68
80
  case @task.status
69
81
  when :running
70
82
  :pending
83
+ when :stopped
84
+ :canceled
71
85
  when :failed
72
86
  :failed
73
87
  when :complete
@@ -91,6 +105,12 @@ module Core
91
105
  status == :failed
92
106
  end
93
107
 
108
+ # [public] Return `true` if canceled.
109
+ #
110
+ def canceled?
111
+ status == :canceled
112
+ end
113
+
94
114
  # [public] Return `true` if complete.
95
115
  #
96
116
  def complete?
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Core
4
4
  module Async
5
- VERSION = "0.2.1"
5
+ VERSION = "0.6.1"
6
6
 
7
7
  def self.version
8
8
  VERSION
data/lib/is/async.rb CHANGED
@@ -29,7 +29,7 @@ module Is
29
29
 
30
30
  # [public] Call behavior synchronously but within an async context, waiting on the result.
31
31
  #
32
- def await
32
+ private def await
33
33
  if (task = ::Async::Task.current?)
34
34
  reference = task.async { |current|
35
35
  begin
@@ -47,11 +47,13 @@ module Is
47
47
  }.result
48
48
  }.wait
49
49
  end
50
+ rescue UncaughtThrowError => error
51
+ throw error.tag, error.value
50
52
  end
51
53
 
52
54
  # [public] Call behavior within an async context without additional nesting.
53
55
  #
54
- def aware
56
+ private def aware
55
57
  if ::Async::Task.current?
56
58
  yield
57
59
  else
@@ -63,7 +65,7 @@ module Is
63
65
 
64
66
  # [public] Sleeps for `seconds` in a proper async context.
65
67
  #
66
- def sleep(seconds)
68
+ private def sleep(seconds)
67
69
  internal_await do |task|
68
70
  task.sleep(seconds)
69
71
  end
@@ -73,29 +75,45 @@ module Is
73
75
  #
74
76
  # Raises `Core::Async::Timeout` if execution exceeds `seconds`.
75
77
  #
76
- def timeout(seconds, &block)
78
+ private def timeout(seconds)
77
79
  internal_await do |task|
80
+ timed_task = internal_async {
81
+ yield
82
+ }
83
+
78
84
  if seconds && seconds > 0
79
85
  task.with_timeout(seconds, Core::Async::Timeout) do
80
- yield
86
+ timed_task.wait
81
87
  end
82
88
  else
83
- yield
89
+ timed_task.wait
84
90
  end
91
+ ensure
92
+ timed_task&.stop
85
93
  end
94
+ rescue UncaughtThrowError => error
95
+ throw error.tag, error.value
86
96
  end
87
97
 
88
98
  # [public] Yields control to allow other fibers to execute.
89
99
  #
90
- def defer
100
+ private def defer
91
101
  if (task = ::Async::Task.current?)
92
102
  task.yield
93
103
  end
94
104
  end
95
105
 
106
+ # [public] Cancels the current async behavior if in progress.
107
+ #
108
+ private def cancel
109
+ if (task = ::Async::Task.current?)
110
+ task.stop
111
+ end
112
+ end
113
+
96
114
  # [public] Resolves a potential future to a final result.
97
115
  #
98
- def resolve(value)
116
+ private def resolve(value)
99
117
  case value
100
118
  when Core::Async::Future
101
119
  value.result
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: core-async
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bryan Powell
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-03-06 00:00:00.000000000 Z
11
+ date: 2021-05-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: async
@@ -54,14 +54,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
54
54
  requirements:
55
55
  - - ">="
56
56
  - !ruby/object:Gem::Version
57
- version: 2.5.0
57
+ version: 2.6.7
58
58
  required_rubygems_version: !ruby/object:Gem::Requirement
59
59
  requirements:
60
60
  - - ">="
61
61
  - !ruby/object:Gem::Version
62
62
  version: '0'
63
63
  requirements: []
64
- rubygems_version: 3.2.4
64
+ rubygems_version: 3.2.15
65
65
  signing_key:
66
66
  specification_version: 4
67
67
  summary: Makes Ruby objects async-aware.