add id to bootloader request actions

This will be used to match didRequest to a requst to avoid issues with messages being queued concurrently
This commit is contained in:
David Lechner
2020-05-21 21:27:47 -05:00
committed by David Lechner
parent 0d57338d71
commit ed5bd4728a
6 changed files with 210 additions and 26 deletions
+26
View File
@@ -0,0 +1,26 @@
import { count, createCountFunc } from './iter';
test('count', () => {
let expected = 0;
for (const i of count()) {
expect(i).toBe(expected);
expected++;
if (expected > 10) {
break;
}
}
});
test('createCountFunc', () => {
const func = createCountFunc();
expect(func()).toBe(0);
expect(func()).toBe(1);
expect(func()).toBe(2);
expect(func()).toBe(3);
expect(func()).toBe(4);
expect(func()).toBe(5);
expect(func()).toBe(6);
expect(func()).toBe(7);
expect(func()).toBe(8);
expect(func()).toBe(9);
});
+19
View File
@@ -0,0 +1,19 @@
/**
* Creates an iterator that counts infinitely (to Number.MAX_SAFE_INTEGER really)
* starting from 0.
*/
export function* count(): Generator<number, number, void> {
let n = 0;
while (true) {
yield n++;
}
}
/**
* Creates a new function that counts infinitely (to Number.MAX_SAFE_INTEGER really)
* starting from 0.
*/
export function createCountFunc(): () => number {
const gen = count();
return (): number => gen.next().value;
}