# Trigger an action repeatedly

**URL:** <https://forums.fusetools.com/t/trigger-an-action-repeatedly/5236>\
**Category:** How-to Discussions\
**Created:** [January 6, 2017, 2:04pm UTC](https://forums.fusetools.com/t/trigger-an-action-repeatedly/5236 "2017-01-06T14:04:33Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Luke](https://avatars.discourse-cdn.com/v4/letter/l/7ab992/32.png) [@Luke](https://forums.fusetools.com/u/Luke)\
**Post date:** [January 6, 2017, 2:04pm UTC](https://forums.fusetools.com/t/trigger-an-action-repeatedly/5236/1 "2017-01-06T14:04:33Z")

</div>

Would that be the best way to repeatedly trigger an event, say once every x seconds?

Something akin to:

```auto
<WhileActive>
	<Repeat Delay="x">
		<Callback Handler="{someJSFunction}"/>
	</Repeat>
</WhileActive>

```

I have an app that needs to periodically check for updates. I am currently attempting to do that in a global js module via a recursive `setTimeout` loop, but sometimes upon page change the js vm seems to forget about timeouts.

As I don’t technically need this callback on all pages, it seems it would make more sense to have something akin to the example code above on each page where I do need it.

Is there anything similiar to `Repeat` or an easy way of doing the above? Cheers

---

<div class="post-metadata">

**Author:** ![edA-qa\_mort-ora-y](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/eda-qa_mort-ora-y/32/124_2.png) [@edA-qa\_mort-ora-y](https://forums.fusetools.com/u/edA-qa_mort-ora-y)\
**Post date:** [January 6, 2017, 6:47pm UTC](https://forums.fusetools.com/t/trigger-an-action-repeatedly/5236/2 "2017-01-06T18:47:29Z")

</div>

`Timeline` has a `PlayMode="Wrap"` option. You can add `Callback` actions with a `Delay`.

---

<div class="post-metadata">

**Author:** ![Luke](https://avatars.discourse-cdn.com/v4/letter/l/7ab992/32.png) [@Luke](https://forums.fusetools.com/u/Luke)\
**Post date:** [January 9, 2017, 3:15pm UTC](https://forums.fusetools.com/t/trigger-an-action-repeatedly/5236/3 "2017-01-09T15:15:22Z")

</div>

How would I activate the `Timeline` with `WhileActive` and have it loop as long as `WhileActive` was above a threshold?

---

<div class="post-metadata">

**Author:** ![edA-qa\_mort-ora-y](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/eda-qa_mort-ora-y/32/124_2.png) [@edA-qa\_mort-ora-y](https://forums.fusetools.com/u/edA-qa_mort-ora-y)\
**Post date:** [January 10, 2017, 7:35am UTC](https://forums.fusetools.com/t/trigger-an-action-repeatedly/5236/4 "2017-01-10T07:35:23Z")

</div>

It does seem that there is no clear way to simply start/stop the animation in `While` trigger using a simple `Change` event. I’m going to make an issue for this.

In the meantime you can pause/resume the playback with something like:

```auto
<WhileActive Bypass="Never">
   <Resume Target="myTimeline" Direction="Forward"/>
   <Pause Target="myTimeline" Direction="Backward"/>
</WhileActive>

```

Also note, I just fixed some issues with `Timeline` in regards to this setup, so an upcoming release should also help out a bit.

---

<div class="post-metadata">

**Author:** ![Luke](https://avatars.discourse-cdn.com/v4/letter/l/7ab992/32.png) [@Luke](https://forums.fusetools.com/u/Luke)\
**Post date:** [January 12, 2017, 1:25pm UTC](https://forums.fusetools.com/t/trigger-an-action-repeatedly/5236/5 "2017-01-12T13:25:41Z")

</div>

Thanks

I have a couple of final questions:

I currently have code which looks like…

```auto
<Timeline ux:Name="myTimeline" PlayMode="Wrap">
	<Callback Handler="{myFunction1}" Delay="2" />
	<Callback Handler="{myFunction2}" Delay="3" />
</Timeline>

<WhileActive Bypass="Never">
	<Resume Target="myTimeline" Direction="Forward" />
	<Pause Target="myTimeline" Direction="Backward" />
</WhileActive>

```

For the `Pause` and `Resume` classes I’m receiving the warnings:

```auto
Deprecated: Use `Trigger.When` instead of `Trigger.Direction` in Fuse.Triggers.Actions.Resume<...\Fuse.Triggers\0.43.11\actions\$.uno:853>
Deprecated: Use `Trigger.When` instead of `Trigger.Direction` in Fuse.Triggers.Actions.Pause<...\Fuse.Triggers\0.43.11\actions\$.uno:853>

```

Am I doing something wrong here, or is this a bug in Fuse?

* * *

When I have items in the timeline, with `PlayMode` on `Wrap` it seems the last action is always skipped (presumably because the timeline immediately wraps back when it reaches the final action, without executing it?). So currently I have to have a placeholder `Callback` at the end of the timeline, in order to stretch it a little.

Is there a better way of handling this?

Thanks

---

<div class="post-metadata">

**Author:** ![edA-qa\_mort-ora-y](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/eda-qa_mort-ora-y/32/124_2.png) [@edA-qa\_mort-ora-y](https://forums.fusetools.com/u/edA-qa_mort-ora-y)\
**Post date:** [January 13, 2017, 6:41am UTC](https://forums.fusetools.com/t/trigger-an-action-repeatedly/5236/6 "2017-01-13T06:41:49Z")

</div>

Use `When="Forward"` instead of `Direction="Forward"`. There were additional options added that aren’t direction-based thus a new name was introduced.

There is a defect in the current release with actions at the ends of wrapping timelines (up to a single frame of actions near the end may be skipped). This is one the issues I fixed; it’ll be available in an upcoming release. Placing those items at the `Delay="0"` instead should work, or extending the timeline as you have done.

---

<div class="post-metadata">

**Author:** ![Luke](https://avatars.discourse-cdn.com/v4/letter/l/7ab992/32.png) [@Luke](https://forums.fusetools.com/u/Luke)\
**Post date:** [January 13, 2017, 12:34pm UTC](https://forums.fusetools.com/t/trigger-an-action-repeatedly/5236/7 "2017-01-13T12:34:25Z")

</div>

Okay. The `When` property sounded like it would have done something different (sounds like a clause, rather than a specifier) to `Direction`.

Cheers.
