项目作者: athanclark

项目描述 :
A simple subscription-esque RPC mechanism using WebSockets, ala the haskell websockets-rpc library (client only)
高级语言: PureScript
项目地址: git://github.com/athanclark/purescript-websockets-rpc.git
创建时间: 2017-03-07T04:32:42Z
项目社区:https://github.com/athanclark/purescript-websockets-rpc

开源协议:BSD 3-Clause "New" or "Revised" License

下载


purescript-websockets-rpc

for use with a websockets-rpc-compliant websocket server,
the purescript-websocket-moderate client
library, and purescript-argonaut json serialization
system.

Example

  1. import WebSocket.RPC
  2. import WebSocket (WEBSOCKET)
  3. data MySubDSL = Foo
  4. deriving (EncodeJson, DecodeJson) -- you should figure this out
  5. data MySupDSL = Bar
  6. deriving (EncodeJson, DecodeJson)
  7. data MyRepDSL = Baz
  8. deriving (EncodeJson, DecodeJson)
  9. data MyComDSL = Qux
  10. deriving (EncodeJson, DecodeJson)
  11. myClient :: forall eff
  12. . {url :: String, protocols :: Array String}
  13. -> (WebSocketClientRPCT MyRepDSL MyComDSL (Eff _) Unit
  14. myClient = rpcClient $ \dispatch -> do
  15. -- could dispatch more than one subscription here
  16. dispatch myClient'
  17. where
  18. myClient' :: RPCClient MySubDSL MySupDSL MyRepDSL MyComDSL (Eff (AllEffs eff))
  19. myClient' =
  20. { subscription: Foo
  21. , onReply: \{supply,cancel} Baz -> do
  22. x <- randomInt 1 10
  23. if x == 10 then cancel else supply Bar
  24. , onComplete: \Qux ->
  25. log "ayooo"
  26. }
  27. main :: Eff _ Unit
  28. main =
  29. execWebSocketClientRPCT $ myClient {url: "ws://localhost", protocols: []}

see the example/ folder for a working one