#!/usr/bin/env ruby
require 'async'
require 'async/http/endpoint'
require 'async/websocket/client'
URL = "wss://polkadot-rpc.dwellir.com"
Async do |task|
endpoint = Async::HTTP::Endpoint.parse(URL)
Async::WebSocket::Client.connect(endpoint) do |connection|
connection.write(Protocol::WebSocket::TextMessage.generate({
"jsonrpc" => "2.0", id: 1, method: "chain_subscribeNewHead", params: []
}))
while message = connection.read
puts message.inspect
end
end
end
This is a very simple program that subscribes to new head and prints out it. I found that when my computer is woken up from sleeping, the program will stop working without any errors.
I'm quite new to this gem and async ruby. How do I handle this situation?