async 2.14.0 → 2.14.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
  SHA256:
3
- metadata.gz: 7074249673c5f7127018a3c609ed127c962c748090959f59a2c3306bf7972a52
4
- data.tar.gz: f3c1149ee1e5483d62a4b19ebb6c6a52fe66b0b27151685f0d939b02727c5768
3
+ metadata.gz: ffbf235f3425b766c8eedfcdb2b03f86569e43ab1cdda3bd44f74c1b25f516b7
4
+ data.tar.gz: 1d71883b2151b5eb0f23daf27221ac091d352809a0ef1f687f282696cd22ae79
5
5
  SHA512:
6
- metadata.gz: 2ea1c73288b49d8f6f5eaeae711b8dc56cd93758dedca4711c52d8caea940eeaaccf423307a3633d7ae2c2317111a1120a143e88ebe15ed57063ec489973214f
7
- data.tar.gz: a2f2d68e6fac9168d91401f907f633f99a6a4f9e323007f72d5bfa6884f1e3b30968ee8bc8a7602c36351c0f3d3b7f28ab922297c41e92a56cd8cd9009956991
6
+ metadata.gz: a00499f9ea43ffee3e6a5cf65dee14f67c5dcd167cb68e1b5da7c11bcef51c06da9c8c2d7a0606f72e5802520f7b9837f128d8425ade3de75111ca16a4cc9c10
7
+ data.tar.gz: f65b60522c85e07a17fdc345944c06e7447095682afea0bd2b7dcbf462deeeb7dcb6053e82eefc96cc259b10d6b0849803b8f22356feb10a21666a5ab134f6d6
checksums.yaml.gz.sig CHANGED
Binary file
data/lib/async/task.rb CHANGED
@@ -13,6 +13,8 @@ require 'console/event/failure'
13
13
  require_relative 'node'
14
14
  require_relative 'condition'
15
15
 
16
+ Fiber.attr_accessor :async_task
17
+
16
18
  module Async
17
19
  # Raised when a task is explicitly stopped.
18
20
  class Stop < Exception
@@ -186,6 +188,15 @@ module Async
186
188
 
187
189
  schedule do
188
190
  @block.call(self, *arguments)
191
+ rescue => error
192
+ # I'm not completely happy with this overhead, but the alternative is to not log anything which makes debugging extremely difficult. Maybe we can introduce a debug wrapper which adds extra logging.
193
+ if @finished.nil?
194
+ Console::Event::Failure.for(error).emit("Task may have ended with unhandled exception.", severity: :warn)
195
+ # else
196
+ # Console::Event::Failure.for(error).emit(self, severity: :debug)
197
+ end
198
+
199
+ raise
189
200
  end
190
201
  else
191
202
  raise RuntimeError, "Task already running!"
@@ -316,13 +327,13 @@ module Async
316
327
  # @returns [Task]
317
328
  # @raises[RuntimeError] If task was not {set!} for the current fiber.
318
329
  def self.current
319
- Thread.current[:async_task] or raise RuntimeError, "No async task available!"
330
+ Fiber.current.async_task or raise RuntimeError, "No async task available!"
320
331
  end
321
332
 
322
333
  # Check if there is a task defined for the current fiber.
323
334
  # @returns [Interface(:async) | Nil]
324
335
  def self.current?
325
- Thread.current[:async_task]
336
+ Fiber.current.async_task
326
337
  end
327
338
 
328
339
  # @returns [Boolean] Whether this task is the currently executing task.
@@ -358,12 +369,6 @@ module Async
358
369
  def failed!(exception = false)
359
370
  @result = exception
360
371
  @status = :failed
361
-
362
- if $DEBUG
363
- Fiber.blocking do
364
- $stderr.puts "Task #{self} failed:", exception.full_message
365
- end
366
- end
367
372
  end
368
373
 
369
374
  def stopped!
@@ -394,11 +399,8 @@ module Async
394
399
 
395
400
  def schedule(&block)
396
401
  @fiber = Fiber.new(annotation: self.annotation) do
397
- set!
398
-
399
402
  begin
400
403
  completed!(yield)
401
- # Console.debug(self) {"Task was completed with #{@children.size} children!"}
402
404
  rescue Stop
403
405
  stopped!
404
406
  rescue StandardError => error
@@ -414,13 +416,9 @@ module Async
414
416
  end
415
417
  end
416
418
 
419
+ @fiber.async_task = self
420
+
417
421
  self.root.resume(@fiber)
418
422
  end
419
-
420
- # Set the current fiber's `:async_task` to this task.
421
- def set!
422
- # This is actually fiber-local:
423
- Thread.current[:async_task] = self
424
- end
425
423
  end
426
424
  end
data/lib/async/version.rb CHANGED
@@ -4,5 +4,5 @@
4
4
  # Copyright, 2017-2024, by Samuel Williams.
5
5
 
6
6
  module Async
7
- VERSION = "2.14.0"
7
+ VERSION = "2.14.1"
8
8
  end
data/readme.md CHANGED
@@ -19,20 +19,17 @@ Async is a composable asynchronous I/O framework for Ruby based on [io-event](ht
19
19
 
20
20
  Please see the [project documentation](https://socketry.github.io/async/) for more details.
21
21
 
22
- - [Getting Started](https://socketry.github.io/async/guides/getting-started/index) - This guide shows how to add
23
- async to your project and run code asynchronously.
22
+ - [Getting Started](https://socketry.github.io/async/guides/getting-started/index) - This guide shows how to add async to your project and run code asynchronously.
24
23
 
25
- - [Asynchronous Tasks](https://socketry.github.io/async/guides/asynchronous-tasks/index) - This guide explains how
26
- asynchronous tasks work and how to use them.
24
+ - [Asynchronous Tasks](https://socketry.github.io/async/guides/asynchronous-tasks/index) - This guide explains how asynchronous tasks work and how to use them.
27
25
 
28
- - [Event Loop](https://socketry.github.io/async/guides/event-loop/index) - This guide gives an overview of how the
29
- event loop is implemented.
26
+ - [Event Loop](https://socketry.github.io/async/guides/event-loop/index) - This guide gives an overview of how the event loop is implemented.
30
27
 
31
- - [Compatibility](https://socketry.github.io/async/guides/compatibility/index) - This guide gives an overview of the
32
- compatibility of Async with Ruby and other frameworks.
28
+ - [Compatibility](https://socketry.github.io/async/guides/compatibility/index) - This guide gives an overview of the compatibility of Async with Ruby and other frameworks.
33
29
 
34
- - [Best Practices](https://socketry.github.io/async/guides/best-practices/index) - This guide gives an overview of
35
- best practices for using Async.
30
+ - [Best Practices](https://socketry.github.io/async/guides/best-practices/index) - This guide gives an overview of best practices for using Async.
31
+
32
+ - [Debugging](https://socketry.github.io/async/guides/debugging/index) - This guide explains how to debug issues with programs that use Async.
36
33
 
37
34
  ## Contributing
38
35
 
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: async
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.14.0
4
+ version: 2.14.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
@@ -62,7 +62,7 @@ cert_chain:
62
62
  Q2K9NVun/S785AP05vKkXZEFYxqG6EW012U4oLcFl5MySFajYXRYbuUpH6AY+HP8
63
63
  voD0MPg1DssDLKwXyt1eKD/+Fq0bFWhwVM/1XiAXL7lyYUyOq24KHgQ2Csg=
64
64
  -----END CERTIFICATE-----
65
- date: 2024-07-14 00:00:00.000000000 Z
65
+ date: 2024-07-15 00:00:00.000000000 Z
66
66
  dependencies:
67
67
  - !ruby/object:Gem::Dependency
68
68
  name: console
metadata.gz.sig CHANGED
Binary file