# Wolfram Mathematica

## Multi-User Countdown Clock

Define a channel that displays a countdown clock and a function that drives the countdown.

In[1]:=
```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]=
In[2]:=
```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]:=
`listener = ChannelListen["Countdown"]`
Out[3]=

Set up a countdown for a certain number of seconds and click the button to start.

In[4]:=
`countdown[20]`
Out[4]=

The clock updates while the countdown runs, unless you pause it.

Out[5]=

Other users can subscribe to your countdown clock by referring to your channel in ChannelListen.

In[6]:=
`\$WolframID <> ":Countdown"`
Out[6]=
In[7]:=
```\$WolframID <> ":Countdown"; ChannelListen[%]```
Out[7]=