зеркало из https://github.com/github/ruby.git
Fix indents in NEWS [ci skip]
The MarkDown parser in RDoc requires 4 columns indentation for paragraphs following list items. Otherwise, the following paragraphs are not interpreted as the part of the preceeding list item,
This commit is contained in:
Родитель
0436f1e15a
Коммит
01790de9e6
58
NEWS.md
58
NEWS.md
|
@ -104,42 +104,44 @@ Note: We're only listing outstanding class updates.
|
||||||
|
|
||||||
* Fiber
|
* Fiber
|
||||||
|
|
||||||
* Introduce `Fiber.[]` and `Fiber.[]=` for inheritable fiber storage.
|
* Introduce Fiber.[] and Fiber.[]= for inheritable fiber storage.
|
||||||
Introduce `Fiber#storage` and `Fiber#storage=` (experimental) for getting
|
Introduce Fiber#storage and Fiber#storage= (experimental) for
|
||||||
and resetting the current storage. Introduce `Fiber.new(storage:)` for
|
getting and resetting the current storage. Introduce
|
||||||
setting the storage when creating a fiber. [[Feature #19078]]
|
`Fiber.new(storage:)` for setting the storage when creating a
|
||||||
|
fiber. [[Feature #19078]]
|
||||||
|
|
||||||
Existing Thread and Fiber local variables can be tricky to use. Thread
|
Existing Thread and Fiber local variables can be tricky to use.
|
||||||
local variables are shared between all fibers, making it hard to isolate,
|
Thread local variables are shared between all fibers, making it
|
||||||
while Fiber local variables can be hard to share. It is often desirable
|
hard to isolate, while Fiber local variables can be hard to
|
||||||
to define unit of execution ("execution context") such that some state
|
share. It is often desirable to define unit of execution
|
||||||
is shared between all fibers and threads created in that context. This is
|
("execution context") such that some state is shared between all
|
||||||
what Fiber storage provides.
|
fibers and threads created in that context. This is what Fiber
|
||||||
|
storage provides.
|
||||||
|
|
||||||
```ruby
|
```ruby
|
||||||
def log(message)
|
def log(message)
|
||||||
puts "#{Fiber[:request_id]}: #{message}"
|
puts "#{Fiber[:request_id]}: #{message}"
|
||||||
end
|
end
|
||||||
|
|
||||||
def handle_requests
|
|
||||||
while request = read_request
|
|
||||||
Fiber.schedule do
|
|
||||||
Fiber[:request_id] = SecureRandom.uuid
|
|
||||||
|
|
||||||
request.messages.each do |message|
|
def handle_requests
|
||||||
Fiber.schedule do
|
while request = read_request
|
||||||
log("Handling #{message}") # Log includes inherited request_id.
|
Fiber.schedule do
|
||||||
|
Fiber[:request_id] = SecureRandom.uuid
|
||||||
|
|
||||||
|
request.messages.each do |message|
|
||||||
|
Fiber.schedule do
|
||||||
|
log("Handling #{message}") # Log includes inherited request_id.
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
```
|
||||||
```
|
|
||||||
|
|
||||||
You should generally consider Fiber storage for any state which you want
|
You should generally consider Fiber storage for any state which
|
||||||
to be shared implicitly between all fibers and threads created in a given
|
you want to be shared implicitly between all fibers and threads
|
||||||
context, e.g. a connection pool, a request id, a logger level,
|
created in a given context, e.g. a connection pool, a request
|
||||||
environment variables, configuration, etc.
|
id, a logger level, environment variables, configuration, etc.
|
||||||
|
|
||||||
* Fiber::Scheduler
|
* Fiber::Scheduler
|
||||||
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче