« first day (1449 days earlier)      last day (2075 days later) » 

6:17 PM
okay, I rewrote it:
I have simplified NValue type
type State = | Free | Pending | Notified of DateTime

type NValue = {
    ID: int
    Value : int
    State : State
    CValue : int
}
created two messages:
type Msg = | UpdateSome of int | MBShow of int * DateTime
first one for "updating" values:
let itemsHandler count (dispatch : Dispatch<_>) token =
    let rec forever count =
        async {
            do! Async.Sleep (rnd.Next 10 * 1000)
            let id = rnd.Next count
            UpdateSome id |> dispatch
            return! forever count
        }

    Async.Start(forever count, token)
and next one for handling time when MB will have closed
let update (dispatch: Dispatcher<Msg>) message model =
    let isEnb = Array.forall (fun nv -> nv.State = Free) model.Values
    match message with
    |UpdateSome id ->
        let nv = rnd.Next 100
        let ni = {model.Values.[id] with Value = nv} |> stUpd
        printfn "[%A] = %A / %A" id nv ni.State
        if ni.State = Free && ni.Value > ni.CValue then
            async {
                MessageBox.Show(Types.message ni)
                return MBShow (id, DateTime.Now)
            } |> dispatch.DispatchAsync
and put it together:
let application count nav =
    let handler = new Executor<_,_>(itemsHandler count)
    handler.Start()
    let model = {Values = gen count; IsEnabled = true}
    let updates = Dispatcher<Msg>()
    Framework.application model (update updates) mainComponent nav
    |> Framework.withDispatcher handler
    |> Framework.withDispatcher updates
 
looks cleaner to me
 
yep, for me too - better and more flexible
but here a question: Framework.withDispatcher works with Executor just fine. Is it okay?
 
6:32 PM
yeah
 
6:46 PM
so, in practice there is no real difference which function to use for Executor?
 
Using withExecutor also subscribes to the executor
if you use withDispatcher, you ignore the executor's notifications
an executor lets you also pass something that turns it on/off depending on the model state
in your case, I'd just make handler a Dispatcher instead of an Executor
 
thank you, seems like I got it (not for 100% but at least enough for this time)
 
think of it like this: "executor" is a specific type of dispatcher which can enable/disable itself based on the current model state
so you can turn on or off whether somethign is running based off something in the model
(that's what it's for)
if you use withDispatcher it doesn't know to listen to the model - so that part of it doesn't work - withExecutor is just withDispatcher + withSubscription
 
7:16 PM
now it's clear, I'll try to not forget it until next time of using Executor
 
7:37 PM
Guy. who I help, uses C# (it's a huge old project without MVVM), so maybe it won't so easy to rewrite
 

« first day (1449 days earlier)      last day (2075 days later) »