I hereby claim:
- I am whitelizard on github.
- I am whitelizard (https://keybase.io/whitelizard) on keybase.
- I have a public key ASDQQj8ThUyAUGANASXBwYlA-tT0kJ4sMe5qFwRZSvs8-Ao
To claim this, I am signing this object:
I hereby claim:
To claim this, I am signing this object:
describe('publish/subscribe 1', () => { | |
it('should send a message from publish to subscribe', async () => { | |
let result; | |
subscribe('ch1', (msg) => (result = msg)); | |
publish('ch1', 1); | |
await wait(900); | |
expect(result).toBe(1); | |
}); | |
}); |
const triggerPromise = () => { | |
let resolve; | |
const promise = new Promise(r => (resolve = r)); | |
return [promise, resolve]; | |
}; |
describe('publish/subscribe 2', () => { | |
it('should send a message from publish to subscribe', async () => { | |
let result; | |
const [promise, resolve] = triggerPromise(); | |
subscribe('ch1', (msg) => { | |
result = msg; | |
resolve(); | |
}); | |
publish('ch1', 1); | |
await promise; |
const asyncWithTimeout = (promise, timeout = 900) => | |
Promise.race([ | |
promise, | |
new Promise((_, reject) => | |
setTimeout(() => reject(Error('Async timeout')), timeout) | |
), | |
]); |
describe('publish/subscribe 3', () => { | |
it('should send a message from publish to subscribe', async () => { | |
let result; | |
const [promise, resolve] = triggerPromise(); | |
subscribe('ch1', (msg) => { | |
result = msg; | |
resolve(); | |
}); | |
publish('ch1', 1); | |
await asyncWithTimeout(promise); |
// item and items are predefined | |
const parent = items[item.parent]; | |
const types = parent.types; | |
const name = parent.name; |
const parentId = item.parent; | |
const parent = parentId ? (items[parentId] || {}) : {}; | |
const types = parent.types || []; | |
const name = parent.name || 'Noname'; |
const { parent: parentId } = item; | |
const { [parentId]: { types = [], name = 'Noname' } = {} } = items; |
class Circle { | |
constructor(pos = [0, 0], r = 0) { | |
this.pos = pos; | |
this.radius = r; | |
this.hitCount = 0; | |
} | |
get r() { | |
return this.radius; | |
} |