I was asking about ports with a request/response pattern here:
Which led to looking at this package:
@brian-watkins I really like the idea of this package. Particularly its
Procedure abstraction which is monadic with its
andThen functions. Its a really nice way of expressing a state machine that processes a sequence of events, whilst also unifying the Elm event stream accross
Task. Just not sure it actually does what I want it to? Has anyone experience of using it?
Its the docs for
filter that are throwing me off a bit. Procedure.Channel - elm-procedure 1.1.0
Filter messages received by whatever subscription is listening on this channel.
For example, you might need to send a command over a port and then wait for a response via a port subscription. You could accomplish that like so:
Channel.open (\key -> myPortCommand key) |> Channel.connect myPortSubscription |> Channel.filter (\key data -> data.key == key) |> Channel.acceptOne |> Procedure.run ProcedureTagger DataTagger
In this example, we pass the channel key through the port and use it to filter incoming subscription messages. This allows us to associate the messages we receive with a particular channel (and procedure), in case multiple procedures with channels that utilize this subscription are running simultaneously.
Looking through the sources I didn’t find a
Dict key (Value -> msg). The idea being that multiple requests could be in flight at the same time with different keys, and when they complete, a function that was set up at the start of the request is then used to build the response message from what comes back in the port.
Applying a filter suggests to me that what comes back in the subscritpion port will hit a filter and potentially be stopped at that point. I don’t see how the request-response pair is being bound to its key, in such a way that multiple request-response pairs can run concurrently.