dimitarvp
Hey everyone,
If I want to stream data from a file, it’s mega easy:
File.stream!("/path/to/file")
|> Stream.map(...)
|> Stream.filter(...)
|> ...consume the processed data here...
|> Stream.run
Is there a way to do the same with a network stream? If there is, I have no idea how to replace File.stream! with it. I dabbled in :gen_tcp but it does not seem to be compatible with Elixir’s Stream module (or IO for that matter).
What I am looking for is a data-origin-neutral way to stream receive data. In the above example that means I only want to be swapping out the top line and everything else must stay the same. It this possible?
Thank you.
Trending in Questions
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
Hello,
I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
So my question is quite simple and i have found no conclusive answer on forum, google or AI.
Should we use :erlang.float for Integer to ...
New
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New
apply_graft/2 doesn’t rewrite an add_many sub-workflow’s deps on an add step. Grafted jobs cancel with “upstream job was deleted”
Version...
New
Other Trending Topics
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hi there! We created Gust: A task orchestrator inspired by Airflow.
For those who have never heard about Aiflow, it’s a Python-based wor...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve.
They are GUI (Emerge) and State management (S...
New
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #ai
- #elixirconf-us
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
blatyo
I’m not aware of anything that already exists for that. Which implies in no way that there isn’t.
It’s not clear to me how network errors should be handled in a stream.
That said, I could imagine something like:
The dynamic supervisor would start up a GenServer that responded to those calls and did something appropriate with them.
NOTE: Assume there are probably errors
dimitarvp
It seems it is me who has to create a
Or a struct plus protocol.
GenServerproxy which handles the same messages while allowing different kinds of streams encapsulated in it.As much as we bash it sometimes here, Go’s uniform I/O is extremely useful.
peerreynders
I’m not entirely sure that your networked use case is a good fit for
Stream - Elixir
I could be off base but I view Elixir Streams as a largely sequential programming construct to feature laziness.
When is it comes to networked, i.e. distributed communication, concurrent programming can actually make certain things simpler - processes are supposed to be used to implement protocols and processes aren’t supposed to be a big deal when they are appropriate.
dimitarvp
In this case, I would like to feed data to a function that requires a normal Elixir
Stream(basically an object that is anEnumerableand aCollectable, namelyIO.Stream). It’s quite easy to figure out how to do that with files and even wrap a stream around a string but I cannot find a way to feed it a network stream (random example: the VLC player fire-hosing a movie on the local network) to Elixir’sStreamfunctions likemapandfilter. I am looking for a way to have anIO.Streamwhich reads data from network and can write data to network (bi-directional).In Go, I can just have a Reader and Writer instances which internally can be based off of anything – files, buffers, network sockets, you name it. In Elixir, I cannot find a way to do it with connected sockets.
Simply put, I am writing a tool that accepts a stream, filters / transforms it, and outputs another stream. It can work with streams based on files and string buffers but not based on connected sockets. So I guess I will end up just doing something like this:
…and just pass the
:stdiostream to my function.peerreynders
IO.binstream/2seems to accept apidwhich suggests that there is some kind of protocol a process can follow to act as the source of a stream (keeping in mind that data doesn’t push though streams).dimitarvp
The problem is exactly that, I cannot get a PID for a connected network socket. See below.
For a quick test (this brings up a small HTTP server):
I tried getting the PID contained inside the
Portthat a:gen_tcpreturns to you and duplicate a request thatcurlexecutes successfully:…and that hangs.
At this point I accepted that I severely misunderstand something so I came here looking for help.
peerreynders
You’ve already been pointed to
resource/3which seems to be used here.The other option seems to be going low level, i.e.: The Erlang I/O Protocol
dimitarvp
I cannot understand the relevance of the article after I’ve read it. If you are telling me I have to devise my own means to somehow model generic input/output stream (that can also use a connected socket underneath, not only files or string IO objects) then yes, I am kind of gathering that myself while scanning Elixir’s stdlib. I’ll see if I can find anything more.
Hmm, maybe. Scanning through it quickly, it doesn’t seem to directly address my problem.
yurko
Not sure if that’s what you’re looking for but here are my two cents: hackney can stream using async option:
https://github.com/benoitc/hackney#get-a-response-asynchronously
you could then use GenStage to do the processing, here’s somewhat related comment Close an async request manually · Issue #103 · edgurgel/httpoison · GitHub
dimitarvp
@yurko Does hackney give you a PID that is the connected network socket?