I’m not sure if this is an HTTP.jl
usage question or really a design question, but in any case…
I’m trying to code an application for which I can seamlessly swap the bit that provides it with streaming data, and I want to be able to support both websockets and plain text files.
So right now I have for the websockets version, something like this:
HTTP.WebSockets.open(wsuri) do ws
write(ws, ws_auth_msg)
write(ws, subscribe_msg)
while true
# my app code
end
end
for the file version I have
lines = open("streaming_data.txt") do f
readlines(f)
end;
for line in lines
# my app code
end
I would like the two situations be more similar. I would like something like
mutable struct App
stream::DataStream
# other things
end
function run(app::App)
for line in app.stream
# my app code
end
end
app = App(stream)
run(app)
So, first question is: is this a reasonable design? Second question is: if so, how do I wrap an HTTP.jl
websocket in a way that achieves this?
EDIT: I quite like the iterator syntax:
while ~isempty(it)
x = popfirst!(it)
# my app
end
To use with the file, we could do
lines = open("streaming_data.txt") do f
readlines(f)
end;
it = Iterators.Stateful(lines)
while ~isempty(it)
# my app
end
What about the HTTP.jl
websocket?