-
-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Concurrency | ||
{id: concurrency} | ||
|
||
## Send and receive | ||
{id: send-and-receive} | ||
{i: Channel} | ||
{i: send} | ||
{i: receive} | ||
{i: spawn} | ||
|
||
 | ||
|
||
## Concurrent HTTP request | ||
{id: concurrent-http-request} | ||
|
||
 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,6 +33,7 @@ | |
"time.md", | ||
"http_client.md", | ||
"process.md", | ||
"concurrency.md", | ||
"other.md" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
require "http/client" | ||
puts "before" | ||
ch = Channel(HTTP::Client::Response).new | ||
|
||
puts "before spawn" | ||
spawn do | ||
puts "in spawn before send" | ||
res = HTTP::Client.get "https://code-maven.com/" | ||
ch.send res | ||
puts "in spawn after send" | ||
end | ||
|
||
puts "before receive" | ||
res = ch.receive | ||
puts "received #{res.body.size} bytes including this row: #{res.body.lines.select(/<title>/)}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
puts "before" | ||
ch = Channel(Int32).new | ||
|
||
puts "before spawn" | ||
spawn do | ||
puts "in spawn before send" | ||
ch.send 42 | ||
puts "in spawn after send" | ||
end | ||
|
||
puts "before receive" | ||
res = ch.receive | ||
puts "received #{res}" |