@@ -412,14 +412,6 @@ module App =
412412
413413 let private log msg = eprintfn $"[skrepka] {msg}"
414414
415− let private asyncCmd (op: Async<Msg>) : Cmd<Msg> =
416− Cmd.ofEffect (fun dispatch ->
417− async {
418− let! msg = op
419− dispatch msg
420− }
421− |> Async.Start)
422−
423415 let private serializeEnvelope =
424416 function
425417 | Envelope.TextMessage(id, body) ->
@@ -503,28 +495,20 @@ module App =
503495 let mapCmd cmdMsg =
504496 match cmdMsg with
505497 | CmdConnect(url, identity) ->
506− asyncCmd (
507− async {
508− try
509− let! token = authenticate url identity
510− return AuthOk token
511− with ex ->
512− return AuthErr ex.Message
513− }
514− )
498+ Cmd.OfAsync.either
499+ (fun (url, id) -> authenticate url id)
500+ (url, identity)
501+ AuthOk
502+ (fun ex -> AuthErr ex.Message)
515503
516504 | CmdSend(session, recipientHex, envelope) ->
517− Cmd.ofEffect (fun dispatch ->
518− async {
519− try
520− do! sendEnvelope session recipientHex envelope
521− with ex ->
522− dispatch (SendFailed ex.Message)
523− }
524− |> Async.Start)
505+ Cmd.OfAsync.attempt
506+ (fun (s, r, e) -> sendEnvelope s r e)
507+ (session, recipientHex, envelope)
508+ (fun ex -> SendFailed ex.Message)
525509
526510 | CmdPoll(session, cursor) ->
527− asyncCmd (
511+ Cmd.ofEffect (fun dispatch ->
528512 async {
529513 log $"poll start cursor={cursor}"
530514
@@ -597,17 +581,17 @@ module App =
597581 | Some e -> $" [{e}]"
598582 | None -> "")
599583
600− return PollResult(events, status, response.Cursor)
584+ dispatch (PollResult(events, status, response.Cursor))
601585 with
602586 | :? TimeoutException ->
603587 log "poll timeout"
604− return PollResult([], "polling...", cursor)
588+ dispatch (PollResult([], "polling...", cursor))
605589 | ex ->
606590 log $"poll error: {ex.Message}"
607591 do! Async.Sleep 3000
608− return PollResult([], $"poll error: {ex.Message}", cursor)
592+ dispatch (PollResult([], $"poll error: {ex.Message}", cursor))
609593 }
610− )
594+ |> Async.Start)
611595
612596 | CmdCopyToClipboard text ->
613597 Cmd.ofEffect (fun _ ->
@@ -615,13 +599,15 @@ module App =
615599 |> ignore)
616600
617601 | CmdLoadState ->
618− asyncCmd (
619− async {
620− match! Store.loadIdentity () with
621− | Some id -> return StateLoaded(Some id, Store.loadData (), Store.loadProfile ())
622− | None -> return StateLoaded(None, None, None)
623− }
624− )
602+ Cmd.OfAsync.perform
603+ (fun () ->
604+ async {
605+ match! Store.loadIdentity () with
606+ | Some id -> return (Some id, Store.loadData (), Store.loadProfile ())
607+ | None -> return (None, None, None)
608+ })
609+ ()
610+ StateLoaded
625611
626612 | CmdSaveIdentity identity -> Cmd.ofEffect (fun _ -> Store.saveIdentity identity |> Async.Start)
627613
@@ -669,6 +655,7 @@ module App =
669655 Label("End-to-end encrypted messaging").font(size = 16.).centerTextHorizontal ()
670656
671657
658+ button "Next" GenIdentity
672659 Button("Generate Identity", GenIdentity).centerHorizontal ()
673660 })
674661 .padding(30.)