I'm beginner in crystal. I have question, maybe somebody can help me.
I use Kemal framework. Have this code:
require "kemal"
require "json"
channel = Channel(Card).new
post "/posts" do |env|
json = JSON.parse(env.request.body as String)
url = json["url"].to_s
spawn do
# Slow process
page = Scraper.new(url)
channel.send(page)
end
{"url" => url}.to_json
end
ws "/" do |socket|
data = channel.receive
socket.send data.to_h.to_json
end
Kemal.run
But the result is sent to web socket only once.
(Only after first post request)
How can I fix it?