async 2.12.1 → 2.16.1

Sign up to get free protection for your applications and to get access to all the features.
data/lib/async/wrapper.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # Released under the MIT License.
4
- # Copyright, 2017-2022, by Samuel Williams.
4
+ # Copyright, 2017-2024, by Samuel Williams.
5
5
  # Copyright, 2017, by Kent Gruber.
6
6
 
7
7
  module Async
@@ -23,6 +23,7 @@ module Async
23
23
 
24
24
  attr_accessor :reactor
25
25
 
26
+ # Dup the underlying IO.
26
27
  def dup
27
28
  self.class.new(@io.dup)
28
29
  end
@@ -51,11 +52,12 @@ module Async
51
52
  @io.to_io.wait(::IO::READABLE|::IO::WRITABLE|::IO::PRIORITY, timeout) or raise TimeoutError
52
53
  end
53
54
 
54
- # Close the io and monitor.
55
+ # Close the underlying IO.
55
56
  def close
56
57
  @io.close
57
58
  end
58
59
 
60
+ # Whether the underlying IO is closed.
59
61
  def closed?
60
62
  @io.closed?
61
63
  end
data/lib/async.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # Released under the MIT License.
4
- # Copyright, 2017-2022, by Samuel Williams.
4
+ # Copyright, 2017-2024, by Samuel Williams.
5
5
  # Copyright, 2020, by Salim Semaoune.
6
6
 
7
7
  require_relative "async/version"
@@ -10,5 +10,6 @@ require_relative "async/reactor"
10
10
  require_relative "kernel/async"
11
11
  require_relative "kernel/sync"
12
12
 
13
+ # Asynchronous programming framework.
13
14
  module Async
14
15
  end
data/lib/kernel/async.rb CHANGED
@@ -24,6 +24,8 @@ module Kernel
24
24
  def Async(...)
25
25
  if current = ::Async::Task.current?
26
26
  return current.async(...)
27
+ elsif scheduler = Fiber.scheduler
28
+ ::Async::Task.run(scheduler, ...)
27
29
  else
28
30
  # This calls Fiber.set_scheduler(self):
29
31
  reactor = ::Async::Reactor.new
data/lib/kernel/sync.rb CHANGED
@@ -18,6 +18,8 @@ module Kernel
18
18
  def Sync(&block)
19
19
  if task = ::Async::Task.current?
20
20
  yield task
21
+ elsif scheduler = Fiber.scheduler
22
+ ::Async::Task.run(scheduler, &block).wait
21
23
  else
22
24
  # This calls Fiber.set_scheduler(self):
23
25
  reactor = Async::Reactor.new
data/license.md CHANGED
@@ -11,7 +11,7 @@ Copyright, 2020-2023, by Olle Jonsson.
11
11
  Copyright, 2020, by Salim Semaoune.
12
12
  Copyright, 2020, by Brian Morearty.
13
13
  Copyright, 2020, by Stefan Wrobel.
14
- Copyright, 2020, by Patrik Wenger.
14
+ Copyright, 2020-2024, by Patrik Wenger.
15
15
  Copyright, 2020, by Ken Muryoi.
16
16
  Copyright, 2020, by Jun Jiang.
17
17
  Copyright, 2020-2022, by Bruno Sutic.
@@ -26,6 +26,7 @@ Copyright, 2023, by Math Ieu.
26
26
  Copyright, 2023, by Emil Tin.
27
27
  Copyright, 2023, by Gert Goet.
28
28
  Copyright, 2024, by Dimitar Peychinov.
29
+ Copyright, 2024, by Jamie McCarthy.
29
30
 
30
31
  Permission is hereby granted, free of charge, to any person obtaining a copy
31
32
  of this software and associated documentation files (the "Software"), to deal
data/readme.md CHANGED
@@ -1,4 +1,4 @@
1
- # ![Async](logo.svg)
1
+ # ![Async](assets/logo.webp)
2
2
 
3
3
  Async is a composable asynchronous I/O framework for Ruby based on [io-event](https://github.com/socketry/io-event).
4
4
 
@@ -19,20 +19,34 @@ 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.
33
+
34
+ ## Releases
35
+
36
+ Please see the [project releases](https://socketry.github.io/async/releases/index) for all releases.
37
+
38
+ ### v2.16.0
39
+
40
+ - [Better Handling of Async and Sync in Nested Fibers](https://socketry.github.io/async/releases/index#better-handling-of-async-and-sync-in-nested-fibers)
41
+
42
+ ## See Also
43
+
44
+ - [async-http](https://github.com/socketry/async-http) — Asynchronous HTTP client/server.
45
+ - [async-websocket](https://github.com/socketry/async-websocket) — Asynchronous client and server websockets.
46
+ - [async-dns](https://github.com/socketry/async-dns) — Asynchronous DNS resolver and server.
47
+ - [falcon](https://github.com/socketry/falcon) — A rack compatible server built on top of `async-http`.
48
+ - [rubydns](https://github.com/ioquatix/rubydns) — An easy to use Ruby DNS server.
49
+ - [slack-ruby-bot](https://github.com/slack-ruby/slack-ruby-bot) — A client for making slack bots.
36
50
 
37
51
  ## Contributing
38
52
 
@@ -46,24 +60,8 @@ We welcome contributions to this project.
46
60
 
47
61
  ### Developer Certificate of Origin
48
62
 
49
- This project uses the [Developer Certificate of Origin](https://developercertificate.org/). All contributors to this project must agree to this document to have their contributions accepted.
50
-
51
- ### Contributor Covenant
52
-
53
- This project is governed by the [Contributor Covenant](https://www.contributor-covenant.org/). All contributors and participants agree to abide by its terms.
54
-
55
- ## See Also
56
-
57
- - [async-io](https://github.com/socketry/async-io) — Asynchronous networking and sockets.
58
- - [async-http](https://github.com/socketry/async-http) — Asynchronous HTTP client/server.
59
- - [async-process](https://github.com/socketry/async-process) — Asynchronous process spawning/waiting.
60
- - [async-websocket](https://github.com/socketry/async-websocket) — Asynchronous client and server websockets.
61
- - [async-dns](https://github.com/socketry/async-dns) — Asynchronous DNS resolver and server.
62
- - [async-rspec](https://github.com/socketry/async-rspec) — Shared contexts for running async specs.
63
+ In order to protect users of this project, we require all contributors to comply with the [Developer Certificate of Origin](https://developercertificate.org/). This ensures that all contributions are properly licensed and attributed.
63
64
 
64
- ### Projects Using Async
65
+ ### Community Guidelines
65
66
 
66
- - [ciri](https://github.com/ciri-ethereum/ciri) An Ethereum implementation written in Ruby.
67
- - [falcon](https://github.com/socketry/falcon) — A rack compatible server built on top of `async-http`.
68
- - [rubydns](https://github.com/ioquatix/rubydns) — An easy to use Ruby DNS server.
69
- - [slack-ruby-bot](https://github.com/slack-ruby/slack-ruby-bot) — A client for making slack bots.
67
+ This project is best served by a collaborative and respectful environment. Treat each other professionally, respect differing viewpoints, and engage constructively. Harassment, discrimination, or harmful behavior is not tolerated. Communicate clearly, listen actively, and support one another. If any issues arise, please inform the project maintainers.
data/releases.md ADDED
@@ -0,0 +1,24 @@
1
+ # Releases
2
+
3
+ ## v2.16.0
4
+
5
+ ### Better Handling of Async and Sync in Nested Fibers
6
+
7
+ Interleaving bare fibers within `Async` and `Sync` blocks should not cause problems, but it presents a number of issues in the current implementation. Tracking the parent-child relationship between tasks, when they are interleaved with bare fibers, is difficult. The current implementation assumes that if there is no parent task, then it should create a new reactor. This is not always the case, as the parent task might not be visible due to nested Fibers. As a result, `Async` will create a new reactor, trying to stop the existing one, causing major internal consistency issues.
8
+
9
+ I encountered this issue when trying to use `Async` within a streaming response in Rails. The `protocol-rack` [uses a normal fiber to wrap streaming responses](https://github.com/socketry/protocol-rack/blob/cb1ca44e9deadb9369bdb2ea03416556aa927c5c/lib/protocol/rack/body/streaming.rb#L24-L28), and if you try to use `Async` within it, it will create a new reactor, causing the server to lock up.
10
+
11
+ Ideally, `Async` and `Sync` helpers should work when any `Fiber.scheduler` is defined. Right now, it's unrealistic to expect `Async::Task` to work in any scheduler, but at the very least, the following should work:
12
+
13
+ ``` ruby
14
+ reactor = Async::Reactor.new # internally calls Fiber.set_scheduler
15
+
16
+ # This should run in the above reactor, rather than creating a new one.
17
+ Async do
18
+ puts "Hello World"
19
+ end
20
+ ```
21
+
22
+ In order to do this, bare `Async` and `Sync` blocks should use `Fiber.scheduler` as a parent if possible.
23
+
24
+ See <https://github.com/socketry/async/pull/340> for more details.
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.12.1
4
+ version: 2.16.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
@@ -9,7 +9,9 @@ authors:
9
9
  - Jeremy Jung
10
10
  - Olle Jonsson
11
11
  - Devin Christensen
12
+ - Patrik Wenger
12
13
  - Emil Tin
14
+ - Jamie McCarthy
13
15
  - Kent Gruber
14
16
  - Brian Morearty
15
17
  - Colin Kelley
@@ -23,7 +25,6 @@ authors:
23
25
  - Masafumi Okura
24
26
  - Masayuki Yamamoto
25
27
  - Math Ieu
26
- - Patrik Wenger
27
28
  - Ryan Musgrave
28
29
  - Salim Semaoune
29
30
  - Shannon Skipper
@@ -62,7 +63,7 @@ cert_chain:
62
63
  Q2K9NVun/S785AP05vKkXZEFYxqG6EW012U4oLcFl5MySFajYXRYbuUpH6AY+HP8
63
64
  voD0MPg1DssDLKwXyt1eKD/+Fq0bFWhwVM/1XiAXL7lyYUyOq24KHgQ2Csg=
64
65
  -----END CERTIFICATE-----
65
- date: 2024-06-23 00:00:00.000000000 Z
66
+ date: 2024-08-26 00:00:00.000000000 Z
66
67
  dependencies:
67
68
  - !ruby/object:Gem::Dependency
68
69
  name: console
@@ -70,20 +71,14 @@ dependencies:
70
71
  requirements:
71
72
  - - "~>"
72
73
  - !ruby/object:Gem::Version
73
- version: '1.25'
74
- - - ">="
75
- - !ruby/object:Gem::Version
76
- version: 1.25.2
74
+ version: '1.26'
77
75
  type: :runtime
78
76
  prerelease: false
79
77
  version_requirements: !ruby/object:Gem::Requirement
80
78
  requirements:
81
79
  - - "~>"
82
80
  - !ruby/object:Gem::Version
83
- version: '1.25'
84
- - - ">="
85
- - !ruby/object:Gem::Version
86
- version: 1.25.2
81
+ version: '1.26'
87
82
  - !ruby/object:Gem::Dependency
88
83
  name: fiber-annotation
89
84
  requirement: !ruby/object:Gem::Requirement
@@ -150,6 +145,7 @@ files:
150
145
  - lib/kernel/sync.rb
151
146
  - license.md
152
147
  - readme.md
148
+ - releases.md
153
149
  homepage: https://github.com/socketry/async
154
150
  licenses:
155
151
  - MIT
metadata.gz.sig CHANGED
Binary file