service { resource R ; shared string question; shared int yes, no; const int WIDTH = 500; html NoVotes =

No one has voted yet!

; html Setup =

The Polling Service

What is the question: ? ; html Form =

The Polling Service

<[question]>?

Yes / No ; html Chart =

The Polling Service

<[question]>?
Yes
<[yes]>
No
<[no]> ; session New() { string q; show Setup receive [q=question]; writer (R) { question = q; yes = no = 0; } exit New vote started!; } session Display() { string q; int y, n; reader (R) { q = question; y = yes; n = no; } if (y + n == 0) exit NoVotes; exit Chart <[question=q, yes=y, no=n, yes_ratio=WIDTH * y / (y + n), no_ratio=WIDTH * n / (y + n)]; } session Vote() { bool answer; show Form <[question=question] receive [answer=answer]; if (answer) yes++; else no++; Display(); } }