Ticker service on steroids

Last year I published a timing service that has a simple task - tick every second and invoke tasks registered to it.
Recently, for a client, I wanted to incorporate it into the project but the requirements meant that I had to refactor the service to be more robust.

So, I created a separated project for it in GitHub with extended capabilities:

  • It was renamed to TickerSrv and published on Bower so you can easily install it in your project.
  • It is now a Provider instead of a Factory. This allows us to configure it’s behavior in the application config phase.
    Currently it only supports configuration for it’s internal interval (defaults to 1000ms), so now you can set it to run at any interval you choose.
  • The service now supports auto task unregister!
    It exposes register and unregister API on the Scope so that when the scope is destroyed, the service intercepts it and unregisters the task automatically.
    You can still register tasks via the service API if you like, but that won’t go through the auto unregister mechanism, so you can avoid auto unregister if you need to.

angular-ticker

A service that is meant to facilitate repetitive tasks that run every X ms.
The TickerSrv service runs every 1000 ms by default.

Task Invocation Policy is determined per task, and defaults to Linear.

  • If the task is configured as Linear, the TickerSrv will wait for the invocation to complete before resetting the task interval (interval is calculated from the moment the invocation is complete).

  • If the task is configured as Parallel (Non-Linear), the TickerSrv will not wait for the invocation to complete before resetting the task interval (interval is calculated from the moment the invocation is started).
    Note, that in this scenario the next invocation might be invoked before the previous one has completed.

For Linear tasks, The handlerFunction is expected to return a promise that is resolved or rejected.
For Parallel tasks, the handlerFunction return value is ignored so returning a promise is not required.

Why use it?

You are probably asking yourself:

Why use it?
Why not just use $timeout/$interval?

Well, the TickerSrv is much more than a simple interval ticker.

Read more…

You are welcomed to read more about it here and visit the GitHub repo here.
Please read the README for the entire documentation.
Feel free to use and abuse. However, if you modify code or add functionalities - please create a pull request for the benefit of others.

Thank you for your interest!

We will contact you as soon as possible.

Send us a message

Oops, something went wrong
Please try again or contact us by email at info@tikalk.com