Repeatidly issue an action, with some time frame in-between.
It's pretty simple to integrate, all you need is:
- a function to determine how much time to wait until the next issue, based onthe total time waited so far:
Time -> Time
- an action to issue, with some data it would expect to apply with
Then, to start the poller, you issueStart
with some data you would want theaction to use. To update this data, just make another call toStart
. Then,to stop the poller, just issueStop
.
importEverytype aliasEveryState={ kickoffCount:Int}type aliasMyModel={ mySession:SessionModel, poller:Every.ModelEveryState}initMyModel:MyModelinitMyModel={ mySession= initSession, poller=Every.init}typeMyAction=SessionMsgSessionMsg|EveryMsg(Every.MsgEveryState)|KickStart-- we're calculating the time to add to the total, based on the current total.fibbDelay:MaybeEveryState->Time->TimefibbDelay_ total= totalissueMsg:MaybeEveryState->MsgissueMsgms=-- ...updateModel:MyAction->MyModel->(MyModel,CmdMyAction)updateModelaction model=caseactionofSessionMsg a->let(newSession, eff)= updateSession a model.mySessionin({ model| mySession= newSession},Cmd.mapSessionMsg eff)EveryMsg a->let(newEvery, eff)= updateEvery fibbDelay issueMsg a model.pollerin({ model| poller= newEvery},Cmd.map(\r->caserofErr x-> x-- resolve issued dataOk x->EveryMsg x) eff)KickStart->( model,Task.perform(Debug.crash<< toString)EveryMsg<|Every.Start{ resetSoFar=True, modifyData=Just<|Every.Update<|\ms->casemsofNothing->{ kickoffCount=1}Just ks->{ kickoffCount= ks.kickoffCount+1}})