Bruno A
Bruno A

Reputation: 127

Primefaces one poll "pause" another poll

I have two primefaces polls in the same page.

One of them (pollLg) has a longer interval time (30 seconds), while the other (pollSm) has a smaller interval (8 seconds).

When pollLg starts, I'd like pollSm to "pause" and then continue (remembering the time it was interrupted) after pollLg finishes its task.

If I call PF('pollSm').stop() and PF('pollSm').start() inside pollLg task, pollSm would be executed again only after 8 seconds.

For example, when the web page opens, I have:

pollSm executions: 8sec, 16sec, 24sec (pollLg will execute here and stop pollSm)

When pollLg finishes, then pollSm would execute only after 8 seconds, and not 2 seconds (it was interrupted with 6 seconds)

Is there any easy way to accomplish this?

Upvotes: 1

Views: 238

Answers (1)

Kukeltje
Kukeltje

Reputation: 12335

Let me start by stating that the PrimeFaces source is open and can be easily used for inspecting (maybe undocumented) features. I did and noticed you can't easily do this in PrimeFaces in the sense that its poll component has a built-in feature. In the javascipt source of the component you can see that it uses plain javascript timers.

So I started searching if you can do this easily in plain javascript and noticed there is no easy feature there either. Luckily there is an existing Q/A in StackOverflow about pausing/resuming a timer in javascript and it even has an answer that is about repeating timers.

If you combine this with overriding (or extending) PrimeFaces widgets, you can achieve what you want.

Upvotes: 2

Related Questions