Skip to content

Commit

Permalink
Add draft of the base class for MessageSystem (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
ForNeVeR committed Jun 12, 2019
1 parent 7daaddf commit bf0c80d
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion Emulsion/MessageSystem.fs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module Emulsion.MessageSystem

open System
open System.Collections.Concurrent
open System.Threading

type IncomingMessageReceiver = IncomingMessage -> unit
Expand All @@ -10,11 +11,21 @@ type IncomingMessageReceiver = IncomingMessage -> unit
type IMessageSystem =
/// Starts the IM connection, manages reconnects. On cancellation could either throw OperationCanceledException or
/// return a unit.
abstract member Run : IncomingMessageReceiver -> CancellationToken -> unit
abstract member Run : CancellationToken -> IncomingMessageReceiver -> unit

/// Queues the message to be sent to the IM system when possible.
abstract member PutMessage : OutgoingMessage -> unit

[<AbstractClass>]
type MessageSystemBase() =
let queue = ConcurrentQueue<OutgoingMessage>()
abstract member Run : CancellationToken -> ConcurrentQueue<OutgoingMessage> -> IncomingMessageReceiver -> unit
interface IMessageSystem with
member this.Run token receiver =
this.Run token queue receiver
member __.PutMessage message =
queue.Enqueue message

type RestartContext = {
token: CancellationToken
cooldown: TimeSpan
Expand Down

0 comments on commit bf0c80d

Please sign in to comment.