-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample-3.ts
385 lines (375 loc) · 13.8 KB
/
example-3.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
import { PartialObserver } from 'rxjs';
import { add, CountdownSegment, CountupSegment, ITimeEmission, Sequencer } from 'sots';
enum AppStates {
Beep = 2,
Warning = 4,
Rest = 8,
Active = 16,
Alert = AppStates.Beep + AppStates.Warning,
}
const observer: PartialObserver<ITimeEmission> = {
next: (value: ITimeEmission): void => {
let output: string = 'time: ' + value.time;
if (value.state) {
output += ' valueOf: ' + value.state.valueOf();
if (value.state.valueOf(AppStates.Alert)) {
output += ' state: \'alert!\'';
} else if (value.state.valueOf(AppStates.Warning)) {
output += ' state: \'warning\'';
} else if (value.state.valueOf(AppStates.Beep)) {
output += ' state: \'beep\'';
}
if (value.state.valueOf(AppStates.Rest)) {
output += ' state: \'rest\'';
} else if (value.state.valueOf(AppStates.Active)) {
output += ' state: \'active\'';
}
}
if (value.interval) {
output += ' interval.current: ' + value.interval.current;
output += ' interval.total: ' + value.interval.total;
}
console.log(output);
},
error: (error: any): void => {
console.error(error);
},
complete: (): void => {
console.log('Play final beep!');
},
};
const sequencer: Sequencer = new Sequencer({ period: 100, compareAsBitwise: true });
sequencer.add(CountdownSegment, {
duration: 10000,
states: [
{ state: AppStates.Beep, timeAt: 'mod1' },
{ state: AppStates.Warning, timeLessThanOrEqualTo: '5' },
],
})
.group(3,
add(CountdownSegment, {
duration: 1000 * 2,
omitFirst: true,
states: [
{ state: AppStates.Rest, timeLessThanOrEqualTo: '2' },
{ state: AppStates.Beep, timeAt: '2' },
],
}),
add(CountdownSegment, {
duration: 1000 * 2,
states: [
{ state: AppStates.Active, timeLessThanOrEqualTo: '2' },
{ state: AppStates.Beep, timeAt: '2' },
],
})
)
.add(CountupSegment, {
duration: 5000,
states: [
{ state: AppStates.Beep, timeAt: '0,3,4' },
{ state: AppStates.Warning, timeGreaterThanOrEqualTo: '3' }],
});
sequencer.subscribe(observer);
setTimeout(() => {
sequencer.start();
console.log('started!');
}, 3000);
setTimeout(() => {
sequencer.pause();
console.log('pausing for 3 seconds until reset.');
}, 6000);
setTimeout(() => {
sequencer.reset();
console.log('reset completed. restarting in 3 seconds.');
}, 9000);
setTimeout(() => {
sequencer.start();
console.log('(re)started!');
}, 12000);
// Output:
/*
started!
time: 10 valueOf: 2 state: 'beep'
time: 9.9
time: 9.8
time: 9.7
time: 9.6
time: 9.5
time: 9.4
time: 9.3
time: 9.2
time: 9.1
time: 9 valueOf: 2 state: 'beep'
time: 8.9
time: 8.8
time: 8.7
time: 8.6
time: 8.5
time: 8.4
time: 8.3
time: 8.2
time: 8.1
time: 8 valueOf: 2 state: 'beep'
time: 7.9
time: 7.8
time: 7.7
time: 7.6
time: 7.5
time: 7.4
time: 7.3
time: 7.2
pausing for 3 seconds until reset.
reset completed. restarting in 3 seconds.
(re)started!
time: 10 valueOf: 2 state: 'beep'
time: 9.9
time: 9.8
time: 9.7
time: 9.6
time: 9.5
time: 9.4
time: 9.3
time: 9.2
time: 9.1
time: 9 valueOf: 2 state: 'beep'
time: 8.9
time: 8.8
time: 8.7
time: 8.6
time: 8.5
time: 8.4
time: 8.3
time: 8.2
time: 8.1
time: 8 valueOf: 2 state: 'beep'
time: 7.9
time: 7.8
time: 7.7
time: 7.6
time: 7.5
time: 7.4
time: 7.3
time: 7.2
time: 7.1
time: 7 valueOf: 2 state: 'beep'
time: 6.9
time: 6.8
time: 6.7
time: 6.6
time: 6.5
time: 6.4
time: 6.3
time: 6.2
time: 6.1
time: 6 valueOf: 2 state: 'beep'
time: 5.9
time: 5.8
time: 5.7
time: 5.6
time: 5.5
time: 5.4
time: 5.3
time: 5.2
time: 5.1
time: 5 valueOf: 6 state: 'alert!'
time: 4.9 valueOf: 4 state: 'warning'
time: 4.8 valueOf: 4 state: 'warning'
time: 4.7 valueOf: 4 state: 'warning'
time: 4.6 valueOf: 4 state: 'warning'
time: 4.5 valueOf: 4 state: 'warning'
time: 4.4 valueOf: 4 state: 'warning'
time: 4.3 valueOf: 4 state: 'warning'
time: 4.2 valueOf: 4 state: 'warning'
time: 4.1 valueOf: 4 state: 'warning'
time: 4 valueOf: 6 state: 'alert!'
time: 3.9 valueOf: 4 state: 'warning'
time: 3.8 valueOf: 4 state: 'warning'
time: 3.7 valueOf: 4 state: 'warning'
time: 3.6 valueOf: 4 state: 'warning'
time: 3.5 valueOf: 4 state: 'warning'
time: 3.4 valueOf: 4 state: 'warning'
time: 3.3 valueOf: 4 state: 'warning'
time: 3.2 valueOf: 4 state: 'warning'
time: 3.1 valueOf: 4 state: 'warning'
time: 3 valueOf: 6 state: 'alert!'
time: 2.9 valueOf: 4 state: 'warning'
time: 2.8 valueOf: 4 state: 'warning'
time: 2.7 valueOf: 4 state: 'warning'
time: 2.6 valueOf: 4 state: 'warning'
time: 2.5 valueOf: 4 state: 'warning'
time: 2.4 valueOf: 4 state: 'warning'
time: 2.3 valueOf: 4 state: 'warning'
time: 2.2 valueOf: 4 state: 'warning'
time: 2.1 valueOf: 4 state: 'warning'
time: 2 valueOf: 6 state: 'alert!'
time: 1.9 valueOf: 4 state: 'warning'
time: 1.8 valueOf: 4 state: 'warning'
time: 1.7 valueOf: 4 state: 'warning'
time: 1.6 valueOf: 4 state: 'warning'
time: 1.5 valueOf: 4 state: 'warning'
time: 1.4 valueOf: 4 state: 'warning'
time: 1.3 valueOf: 4 state: 'warning'
time: 1.2 valueOf: 4 state: 'warning'
time: 1.1 valueOf: 4 state: 'warning'
time: 1 valueOf: 6 state: 'alert!'
time: 0.9 valueOf: 4 state: 'warning'
time: 0.8 valueOf: 4 state: 'warning'
time: 0.7 valueOf: 4 state: 'warning'
time: 0.6 valueOf: 4 state: 'warning'
time: 0.5 valueOf: 4 state: 'warning'
time: 0.4 valueOf: 4 state: 'warning'
time: 0.3 valueOf: 4 state: 'warning'
time: 0.2 valueOf: 4 state: 'warning'
time: 0.1 valueOf: 4 state: 'warning'
time: 2 valueOf: 18 state: 'beep' state: 'active' interval.current: 1 interval.total: 3
time: 1.9 valueOf: 16 state: 'active' interval.current: 1 interval.total: 3
time: 1.8 valueOf: 16 state: 'active' interval.current: 1 interval.total: 3
time: 1.7 valueOf: 16 state: 'active' interval.current: 1 interval.total: 3
time: 1.6 valueOf: 16 state: 'active' interval.current: 1 interval.total: 3
time: 1.5 valueOf: 16 state: 'active' interval.current: 1 interval.total: 3
time: 1.4 valueOf: 16 state: 'active' interval.current: 1 interval.total: 3
time: 1.3 valueOf: 16 state: 'active' interval.current: 1 interval.total: 3
time: 1.2 valueOf: 16 state: 'active' interval.current: 1 interval.total: 3
time: 1.1 valueOf: 16 state: 'active' interval.current: 1 interval.total: 3
time: 1 valueOf: 16 state: 'active' interval.current: 1 interval.total: 3
time: 0.9 valueOf: 16 state: 'active' interval.current: 1 interval.total: 3
time: 0.8 valueOf: 16 state: 'active' interval.current: 1 interval.total: 3
time: 0.7 valueOf: 16 state: 'active' interval.current: 1 interval.total: 3
time: 0.6 valueOf: 16 state: 'active' interval.current: 1 interval.total: 3
time: 0.5 valueOf: 16 state: 'active' interval.current: 1 interval.total: 3
time: 0.4 valueOf: 16 state: 'active' interval.current: 1 interval.total: 3
time: 0.3 valueOf: 16 state: 'active' interval.current: 1 interval.total: 3
time: 0.2 valueOf: 16 state: 'active' interval.current: 1 interval.total: 3
time: 0.1 valueOf: 16 state: 'active' interval.current: 1 interval.total: 3
time: 2 valueOf: 10 state: 'beep' state: 'rest' interval.current: 2 interval.total: 3
time: 1.9 valueOf: 8 state: 'rest' interval.current: 2 interval.total: 3
time: 1.8 valueOf: 8 state: 'rest' interval.current: 2 interval.total: 3
time: 1.7 valueOf: 8 state: 'rest' interval.current: 2 interval.total: 3
time: 1.6 valueOf: 8 state: 'rest' interval.current: 2 interval.total: 3
time: 1.5 valueOf: 8 state: 'rest' interval.current: 2 interval.total: 3
time: 1.4 valueOf: 8 state: 'rest' interval.current: 2 interval.total: 3
time: 1.3 valueOf: 8 state: 'rest' interval.current: 2 interval.total: 3
time: 1.2 valueOf: 8 state: 'rest' interval.current: 2 interval.total: 3
time: 1.1 valueOf: 8 state: 'rest' interval.current: 2 interval.total: 3
time: 1 valueOf: 8 state: 'rest' interval.current: 2 interval.total: 3
time: 0.9 valueOf: 8 state: 'rest' interval.current: 2 interval.total: 3
time: 0.8 valueOf: 8 state: 'rest' interval.current: 2 interval.total: 3
time: 0.7 valueOf: 8 state: 'rest' interval.current: 2 interval.total: 3
time: 0.6 valueOf: 8 state: 'rest' interval.current: 2 interval.total: 3
time: 0.5 valueOf: 8 state: 'rest' interval.current: 2 interval.total: 3
time: 0.4 valueOf: 8 state: 'rest' interval.current: 2 interval.total: 3
time: 0.3 valueOf: 8 state: 'rest' interval.current: 2 interval.total: 3
time: 0.2 valueOf: 8 state: 'rest' interval.current: 2 interval.total: 3
time: 0.1 valueOf: 8 state: 'rest' interval.current: 2 interval.total: 3
time: 2 valueOf: 18 state: 'beep' state: 'active' interval.current: 2 interval.total: 3
time: 1.9 valueOf: 16 state: 'active' interval.current: 2 interval.total: 3
time: 1.8 valueOf: 16 state: 'active' interval.current: 2 interval.total: 3
time: 1.7 valueOf: 16 state: 'active' interval.current: 2 interval.total: 3
time: 1.6 valueOf: 16 state: 'active' interval.current: 2 interval.total: 3
time: 1.5 valueOf: 16 state: 'active' interval.current: 2 interval.total: 3
time: 1.4 valueOf: 16 state: 'active' interval.current: 2 interval.total: 3
time: 1.3 valueOf: 16 state: 'active' interval.current: 2 interval.total: 3
time: 1.2 valueOf: 16 state: 'active' interval.current: 2 interval.total: 3
time: 1.1 valueOf: 16 state: 'active' interval.current: 2 interval.total: 3
time: 1 valueOf: 16 state: 'active' interval.current: 2 interval.total: 3
time: 0.9 valueOf: 16 state: 'active' interval.current: 2 interval.total: 3
time: 0.8 valueOf: 16 state: 'active' interval.current: 2 interval.total: 3
time: 0.7 valueOf: 16 state: 'active' interval.current: 2 interval.total: 3
time: 0.6 valueOf: 16 state: 'active' interval.current: 2 interval.total: 3
time: 0.5 valueOf: 16 state: 'active' interval.current: 2 interval.total: 3
time: 0.4 valueOf: 16 state: 'active' interval.current: 2 interval.total: 3
time: 0.3 valueOf: 16 state: 'active' interval.current: 2 interval.total: 3
time: 0.2 valueOf: 16 state: 'active' interval.current: 2 interval.total: 3
time: 0.1 valueOf: 16 state: 'active' interval.current: 2 interval.total: 3
time: 2 valueOf: 10 state: 'beep' state: 'rest' interval.current: 3 interval.total: 3
time: 1.9 valueOf: 8 state: 'rest' interval.current: 3 interval.total: 3
time: 1.8 valueOf: 8 state: 'rest' interval.current: 3 interval.total: 3
time: 1.7 valueOf: 8 state: 'rest' interval.current: 3 interval.total: 3
time: 1.6 valueOf: 8 state: 'rest' interval.current: 3 interval.total: 3
time: 1.5 valueOf: 8 state: 'rest' interval.current: 3 interval.total: 3
time: 1.4 valueOf: 8 state: 'rest' interval.current: 3 interval.total: 3
time: 1.3 valueOf: 8 state: 'rest' interval.current: 3 interval.total: 3
time: 1.2 valueOf: 8 state: 'rest' interval.current: 3 interval.total: 3
time: 1.1 valueOf: 8 state: 'rest' interval.current: 3 interval.total: 3
time: 1 valueOf: 8 state: 'rest' interval.current: 3 interval.total: 3
time: 0.9 valueOf: 8 state: 'rest' interval.current: 3 interval.total: 3
time: 0.8 valueOf: 8 state: 'rest' interval.current: 3 interval.total: 3
time: 0.7 valueOf: 8 state: 'rest' interval.current: 3 interval.total: 3
time: 0.6 valueOf: 8 state: 'rest' interval.current: 3 interval.total: 3
time: 0.5 valueOf: 8 state: 'rest' interval.current: 3 interval.total: 3
time: 0.4 valueOf: 8 state: 'rest' interval.current: 3 interval.total: 3
time: 0.3 valueOf: 8 state: 'rest' interval.current: 3 interval.total: 3
time: 0.2 valueOf: 8 state: 'rest' interval.current: 3 interval.total: 3
time: 0.1 valueOf: 8 state: 'rest' interval.current: 3 interval.total: 3
time: 2 valueOf: 18 state: 'beep' state: 'active' interval.current: 3 interval.total: 3
time: 1.9 valueOf: 16 state: 'active' interval.current: 3 interval.total: 3
time: 1.8 valueOf: 16 state: 'active' interval.current: 3 interval.total: 3
time: 1.7 valueOf: 16 state: 'active' interval.current: 3 interval.total: 3
time: 1.6 valueOf: 16 state: 'active' interval.current: 3 interval.total: 3
time: 1.5 valueOf: 16 state: 'active' interval.current: 3 interval.total: 3
time: 1.4 valueOf: 16 state: 'active' interval.current: 3 interval.total: 3
time: 1.3 valueOf: 16 state: 'active' interval.current: 3 interval.total: 3
time: 1.2 valueOf: 16 state: 'active' interval.current: 3 interval.total: 3
time: 1.1 valueOf: 16 state: 'active' interval.current: 3 interval.total: 3
time: 1 valueOf: 16 state: 'active' interval.current: 3 interval.total: 3
time: 0.9 valueOf: 16 state: 'active' interval.current: 3 interval.total: 3
time: 0.8 valueOf: 16 state: 'active' interval.current: 3 interval.total: 3
time: 0.7 valueOf: 16 state: 'active' interval.current: 3 interval.total: 3
time: 0.6 valueOf: 16 state: 'active' interval.current: 3 interval.total: 3
time: 0.5 valueOf: 16 state: 'active' interval.current: 3 interval.total: 3
time: 0.4 valueOf: 16 state: 'active' interval.current: 3 interval.total: 3
time: 0.3 valueOf: 16 state: 'active' interval.current: 3 interval.total: 3
time: 0.2 valueOf: 16 state: 'active' interval.current: 3 interval.total: 3
time: 0.1 valueOf: 16 state: 'active' interval.current: 3 interval.total: 3
time: 0 valueOf: 2 state: 'beep'
time: 0.1
time: 0.2
time: 0.3
time: 0.4
time: 0.5
time: 0.6
time: 0.7
time: 0.8
time: 0.9
time: 1
time: 1.1
time: 1.2
time: 1.3
time: 1.4
time: 1.5
time: 1.6
time: 1.7
time: 1.8
time: 1.9
time: 2
time: 2.1
time: 2.2
time: 2.3
time: 2.4
time: 2.5
time: 2.6
time: 2.7
time: 2.8
time: 2.9
time: 3 valueOf: 6 state: 'alert!'
time: 3.1 valueOf: 4 state: 'warning'
time: 3.2 valueOf: 4 state: 'warning'
time: 3.3 valueOf: 4 state: 'warning'
time: 3.4 valueOf: 4 state: 'warning'
time: 3.5 valueOf: 4 state: 'warning'
time: 3.6 valueOf: 4 state: 'warning'
time: 3.7 valueOf: 4 state: 'warning'
time: 3.8 valueOf: 4 state: 'warning'
time: 3.9 valueOf: 4 state: 'warning'
time: 4 valueOf: 4 state: 'warning'
time: 4.1 valueOf: 4 state: 'warning'
time: 4.2 valueOf: 4 state: 'warning'
time: 4.3 valueOf: 4 state: 'warning'
time: 4.4 valueOf: 4 state: 'warning'
time: 4.5 valueOf: 4 state: 'warning'
time: 4.6 valueOf: 4 state: 'warning'
time: 4.7 valueOf: 4 state: 'warning'
time: 4.8 valueOf: 4 state: 'warning'
time: 4.9 valueOf: 4 state: 'warning'
Play final beep!
*/