Skip to content

Commit

Permalink
Work around dotnet/fsharp#16524
Browse files Browse the repository at this point in the history
  • Loading branch information
ForNeVeR committed Feb 5, 2024
1 parent e577f4f commit 838e966
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions Emulsion/Xmpp/XmppMessageSystem.fs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ open Emulsion.Settings
type XmppMessageSystem(ctx: ServiceContext, cancellationToken: CancellationToken, settings: XmppSettings) =
inherit MessageSystemBase(ctx, cancellationToken)

let client = ref None
let mutable client = None

member private _.BaseRunAsync r = base.RunAsync r

Expand All @@ -21,20 +21,20 @@ type XmppMessageSystem(ctx: ServiceContext, cancellationToken: CancellationToken
let newClient = SharpXmppClient.wrap sharpXmpp |> EmulsionXmpp.initializeLogging ctx.Logger
use newClientLifetimeDef = Lifetime.Define()
try
Volatile.Write(client, Some (newClient, newClientLifetimeDef.Lifetime))
Volatile.Write(&client, Some (newClient, newClientLifetimeDef.Lifetime))
do! this.BaseRunAsync receiver
finally
Volatile.Write(client, None)
Volatile.Write(&client, None)
}

override _.RunUntilError receiver = async {
match Volatile.Read client with
match Volatile.Read &client with
| Some(client, _) -> return! EmulsionXmpp.run settings ctx.Logger client receiver
| None -> return failwith "The system cannot be run: the connection is not established"
}

override _.Send (OutgoingMessage message) = async {
match Volatile.Read(client) with
match Volatile.Read &client with
| None -> failwith "Client is offline"
| Some (client, lt) ->
return! EmulsionXmpp.send ctx.Logger client lt settings message
Expand Down

0 comments on commit 838e966

Please sign in to comment.