Guest User

Untitled

a guest
Jun 22nd, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. /// A raw message.
  2. type Message = byte[]
  3.  
  4. /// A domain-specific input type.
  5. type Input =
  6. | MerchantSkuImported
  7. | MerchantSkuRemoved
  8.  
  9. /// A domain-specific output type.
  10. type Output =
  11. | SkuUpdated
  12.  
  13. /// Decodes an input or returns an error.
  14. let decodeInput : Message -> Result<Input, string> = undef
  15.  
  16. /// Encodes the output.
  17. let encodeOutput : Output -> Message = undef
  18.  
  19. /// Runs the core logic of the service.
  20. let handle : Input -> Async<Output> = undef
  21.  
  22. /// Given a host name, returns a stream of input messages.
  23. let inputStream : string -> AsyncSeq<Message> = undef
  24.  
  25. /// Given a host name, publishes an output message.
  26. let publish : string -> Message -> Async<unit> = undef
  27.  
  28. /// Creates a message handler given a decoder, business logic handler and a decoder.
  29. let handler :
  30. (Message -> Result<Input, string>) ->
  31. (Input -> Async<Output>) ->
  32. (Output -> Async<unit>) ->
  33. Message -> Async<unit> = undef
  34.  
  35. /// Configuration for the service.
  36. type Args = {
  37. input_host : string
  38. output_host : string
  39. }
  40.  
  41. /// Runs the service.
  42. let run (args:Args) = async {
  43. let inputStream = inputStream args.input_host
  44. let publish = publish args.output_host
  45. let handle = handler decodeInput handle (encodeOutput >> publish)
  46. do! inputStream |> AsyncSeq.iterAsync handle }
Add Comment
Please, Sign In to add comment