mirror of
https://github.com/pybricks/pybricks-code.git
synced 2026-09-12 09:36:27 +00:00
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:
committed by
David Lechner
parent
0d57338d71
commit
ed5bd4728a
@@ -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);
|
||||
});
|
||||
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user