merge deadlock
parent
536c04bd71
commit
f407c235c7
|
@ -80,19 +80,31 @@ export default class Panda {
|
||||||
|
|
||||||
async canRecv() {
|
async canRecv() {
|
||||||
let result = null,
|
let result = null,
|
||||||
receiptTime = null;
|
receiptTime = null,
|
||||||
|
attempts = 0;
|
||||||
|
|
||||||
while (result === null) {
|
while (result === null) {
|
||||||
try {
|
try {
|
||||||
result = await this.device.transferIn(1, BUFFER_SIZE);
|
result = await this.device.transferIn(1, BUFFER_SIZE);
|
||||||
receiptTime = performance.now() / 1000;
|
receiptTime = performance.now() / 1000;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.warn("can_recv failed, retrying");
|
console.warn("can_recv failed, retrying");
|
||||||
|
attempts = Math.min(++attempts, 10);
|
||||||
|
await wait(attempts * 100);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await wait(0);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
time: receiptTime,
|
time: receiptTime,
|
||||||
canMessages: this.parseCanBuffer(result.data.buffer)
|
canMessages: this.parseCanBuffer(result.data.buffer)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function wait(ms) {
|
||||||
|
return new Promise(function(resolve, reject) {
|
||||||
|
setTimeout(resolve, ms);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue