-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Question: extend Elmish.Bridge to RPC with a ReplyChannel abstraction #29
Comments
I'm not sure if I understand it completely... Would it be the same as the following? Today:
After that:
Is the idea make it possible to write code as the following? let someFunction n =
async {
let! value = Bridge.Ask GiveMeValueA
match value with
| HaveTheValue (Some a) -> return somethingWith a
| _ -> return somethingElse
} If that's it, I like the idea! Maybe |
Yeah something similar like that. I'd make it as similar to the MailboxProcessor as possible, so it could look like this: // defined by Elmish,Bridge
type IReplyChannel<'T> with
abstract member ReplyWithValue : 'T -> unit
abstract member ReplyWithException : exn -> unit
// shared user code
type Msg =
| GiveMeValueA of rc: IReplyChannel<int>
// RPC-Client (web-server)
async {
let! result = hub.Ask(fun rc -> GiveMeValueA rc)
// result is 42
}
// RPC-server (browser)
let update =
match msg with
| GiveMeValueA rc->
rc.ReplyWithValue(42) of course this RPC stuff should be two-way, so that the browser could also "ask" the web-server.
You'd have to transparently track the request / response messages with some internal message ids to correlate them, then add a timeout if the other side doesn't respond after some time, etc ... It would add a bunch of additional hidden state that must be tracked. |
I might have now the knowledge I was missing to implement this feature. I hope to have some fruitful experiments soon! |
@0x53A I added a method Also, I'm not sure what to do for the cases with multiple clients. Would a function callback receiving the I'll try to implement the reverse communication soon. |
Client now has a |
rc-9 changed the transport a little so the message that goes to server is now smaller. |
5.0.0-rc-9-1 now have |
If this is outside the scope of your Vision of Elmish.Bride, please feel free to just close this ;)
I like the elmish concept in general, and I already use and like Elmish.Bridge for pushing data from server to client.
It is really good for one-way, message based communication.
But often you also need a RPC style, request-response flow, and that is a little bit cumbersome with just fire-and-forget messages.
I haven't thought too deeply about it, but what would you think about adding RPC capabilities by emulating some Actor models with a ReplyChannel abstraction?
The proposed API use would look very similar to the MailboxProcessor:
You have a
ReplyChannel
class/interface.On the serverside on the hub, you have
AskClient
/AskClientIf
, similar toBroadcastClient
/SendClientIf
.On the client side you have
Bridge.Ask
, complimentary toBridge.Send
.IMO the
Msg
andupdate
parts of elmish are already very similar to an actor, this would just extend this capability.The text was updated successfully, but these errors were encountered: