Created
November 11, 2019 05:04
-
-
Save rdp/31632b22d99d9e5c2cc815c3d51ca446 to your computer and use it in GitHub Desktop.
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
require "socket" | |
lib C | |
# In C: double cos(double x) | |
fun sleep(value : UInt32) : UInt32 | |
end | |
spawn { | |
loop { | |
TCPSocket.new("facebook.com",80,0.1,0.1).close | |
STDOUT.print "." | |
} | |
} | |
loop { | |
puts "sleeping" | |
Fiber.yield | |
C.sleep(1) # or replace with sleep(1) | |
} |
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
$ crystal bad.cr | |
sleeping | |
sleeping | |
sleeping | |
Unhandled exception in spawn: connect timed out (IO::Timeout) | |
from /usr/share/crystal/src/socket/tcp_socket.cr:75:15 in 'initialize' | |
from /usr/share/crystal/src/socket/tcp_socket.cr:27:3 in 'new' | |
from bad.cr:9:5 in '->' | |
from /usr/share/crystal/src/fiber.cr:255:3 in 'run' | |
from /usr/share/crystal/src/fiber.cr:48:34 in '->' | |
from ??? | |
sleeping |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment