餐厅门口有一台平板,柜台里面还有一台。两台看的是同一条队。
这件事比想象中难。门口的人把客人写进去,柜台的人叫下一桌。两个画面一旦各自开始记「现在四桌」,柜台一安排入座,门口就还是四桌。而那个错位会以「和客人吵架」的形式出现。 那些按月订阅卖排队工具的公司,卖的相当一部分其实就是「不让这个错位发生」。
我们用一个服务器和两个画面做了出来。
门口

一个大数字、一个预计时间、一份列表。门口画面做的就这些。
列表里的「next」「1 ahead」「2 ahead」没有被存下来。 排第几,是从列表的顺序里出来的。
// Position is derived from the list order. Nothing stores
// "you are third" — that would be wrong the moment somebody
// ahead gives up and leaves.
'ahead': i == 0 ? 'next' : '$i ahead',
前面那桌等不下去走了,后面的自动往前挪一位。要是存了下来,就得有人把它们全部重写。
柜台

#41 Han (2),按钮上也写着那一组柜台画面用另一种方式看同一条队。它不是给客人看的,所以挂着每桌等了多久。
counter sees the same 4 parties, front of the line has waited 20 min
the same 4 parties — 这一行就是这篇文章的一半。两个画面各自去问了服务器,拿到了同样的答案。
叫号
在柜台按下按钮,排在最前的那桌就入座。

#42 Oduya (4),THIS SHIFT 显示已入座 1、平均等待 20 min、当前报出 27 min这里同时发生两件事。从列表里消失,在记录里留下。
// The party leaves the waiting list but not the record. An owner who
// wants to know how long people actually waited has to be able to ask
// afterwards, and a deleted row cannot answer.
p.calledAtNote = 'waited ${_now - p.joinedAtMinute} min';
_served.add(p);
画面底部的 seated today: 1 — Han waited 20 min 就是那条记录。老板问「我们家平均等多久」的那一刻要的正是它,而被删掉的行答不上来。
以及没人碰过的门口

这个画面没有人碰过。 只是在柜台按了一次按钮。
door reads: 4 parties, 11 people, about 36 min
counter called: called Han (41) — Han waited 20 min
door now reads: 3 parties, about 27 min — nobody edited this screen
estimate 36 min -> 27 min because the list is 4 -> 3
36 分钟变成 27 分钟,不是因为有人填了个 27。是列表从四变成了三,而预计时间是从列表算出来的。
// The estimate the person at the door reads out loud.
'estimate': '${_waiting.length * _minutesPerTable} min',
_minutesPerTable 是 9。这是老板一辈子可能改一次的数字,所以只有那个数字待在一个地方。