#How do I put a delay here?

1 messages · Page 1 of 1 (latest)

whole smelt
#
Loading: {
            invoke: {
                input: {},
                onDone: [
                    {
                        target: "Loading",
                        guard: {
                            type: "notDone",
                        },
                    },
                    {
                        target: "Done",
                    },
                ],
                onError: {
                    target: "Failure",
                },
                src: "checkProgress",
            },

I have tried this but it doesnt seem to work:

Loading: {
            invoke: {
                input: {},
                onDone: [
                    {
                        after: {
                                                   1000: "Loading"
                                                }
                        guard: {
                            type: "notDone",
                        },
                    },
                    {
                        target: "Done",
                    },
                ],
                onError: {
                    target: "Failure",
                },
                src: "checkProgress",
            },
modest dome
#

Could you describe the behavior you are looking for?

whole smelt
#

Basically want it to transition back to "Loading", so itself if it gets caught by the guard "notDone". That already works here, now I would like it to wait 1s before transition back to it.

modest dome
#

Are you invoking a promise?

#

So you’re trying to load some data and it could resolve with the data or an indication that it’s not done. In the later case you want to wait a second and re-invoke the promise?

whole smelt
modest dome
#

should the promise error if it times out and you check for a specific error in order to try again?

whole smelt
#

No in this case I get a progress value back and I just check for the progress level.
as the "notDone" guard.

modest dome
#

okay gotcha

whole smelt
#
   {
                        target: "Loading",
                        guard: {
                            type: "notDone",
                        },
                    },

Basically want to extend this transition with a delay

modest dome
#

ya in v5 you would have to add a new state called waiting

states: {
  loading:{
    invoke: {
      src: 'checkProgress',
      onDone: [
        { guard: 'notDone', target: 'waiting' },
        'done'
      ],
      onError: 'failure'
    }
  },
  waiting: {
    after: {
      1000: 'loading'
    }
  },
  failure: {},
  done: {},
}
whole smelt
#

Ah gotcha. Thanks

whole smelt