Multi-User Countdown Clock
Define a channel that displays a countdown clock and a function that drives the countdown.
In[1]:=
![Click for copyable input](assets.en/multi-user-countdown-clock/In_72.png)
CreateChannel["Countdown",
HandlerFunctions ->
Association["MessageReceived" -> ((Countdown`$time = #Message) &)],
Initialization :>
CreateWindow[
DocumentNotebook[{Dynamic[
ClockGauge[$time, PlotTheme -> "Business"]]}],
WindowSize -> All, WindowElements -> {}, ShowCellBracket -> False,
Background -> Black, WindowFrameElements -> {"CloseBox"},
Selectable -> False, WindowTitle -> "Countdown",
CellContext -> "Countdown`"],
Permissions ->
Association["All" -> "Read", "Owner" -> {"Write", "Execute"}]]
Out[1]=
![](assets.en/multi-user-countdown-clock/O_70.png)
In[2]:=
![Click for copyable input](assets.en/multi-user-countdown-clock/In_73.png)
countdown[t_] :=
DynamicModule[{paused = True, lbl = "Pause", ii = t, up = None},
Row[{Button[Dynamic[If[paused, "Start", lbl]], paused = ! paused;
up = If[paused, None, UpdateInterval -> 1]],
Dynamic[Refresh[
If[ii >= 0 && ! paused,
" \[LongRightArrow] " <>
TextString[ChannelSend["Countdown", ii--]],
If[ii <= 0, up = None; lbl = "Done"]; ""], up,
TrackedSymbols :> {paused}]]}]]
Subscribe to the channel.
In[3]:=
![Click for copyable input](assets.en/multi-user-countdown-clock/In_74.png)
listener = ChannelListen["Countdown"]
Out[3]=
![](assets.en/multi-user-countdown-clock/O_71.png)
Set up a countdown for a certain number of seconds and click the button to start.
In[4]:=
![Click for copyable input](assets.en/multi-user-countdown-clock/In_75.png)
countdown[20]
Out[4]=
![](assets.en/multi-user-countdown-clock/O_72.png)
The clock updates while the countdown runs, unless you pause it.
Out[5]=
![](assets.en/multi-user-countdown-clock/O_73.png)
Other users can subscribe to your countdown clock by referring to your channel in ChannelListen.
In[6]:=
![Click for copyable input](assets.en/multi-user-countdown-clock/In_76.png)
$WolframID <> ":Countdown"
Out[6]=
![](assets.en/multi-user-countdown-clock/O_74.png)
In[7]:=
![Click for copyable input](assets.en/multi-user-countdown-clock/In_77.png)
$WolframID <> ":Countdown";
ChannelListen[%]
Out[7]=
![](assets.en/multi-user-countdown-clock/O_75.png)