jacdac-ts
Advanced tools
Comparing version 1.32.12 to 1.32.13
@@ -50,2 +50,3 @@ import { Proto } from "./proto"; | ||
talkAsync(cmd: number, data?: Uint8Array): Promise<Uint8Array>; | ||
private enqueueTalk; | ||
private sendMsgAsync; | ||
@@ -52,0 +53,0 @@ onEvent(id: number, f: (buf: Uint8Array) => void): void; |
@@ -23,2 +23,3 @@ import { Proto } from "./proto"; | ||
detectHF2(): Promise<boolean>; | ||
private enqueueTalk; | ||
onJDMessage(f: (buf: Uint8Array) => void): void; | ||
@@ -25,0 +26,0 @@ sendJDMessageAsync(fr: Uint8Array): Promise<void>; |
{ | ||
"name": "jacdac-ts", | ||
"version": "1.32.12", | ||
"version": "1.32.13", | ||
"description": "JavaScript/TypeScript library to interact with Jacdac devices", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -15,3 +15,3 @@ import { Proto } from "./proto" | ||
import { HF2_TIMEOUT } from "../constants" | ||
import { isTimeoutError, throwError } from "../error" | ||
import { isCancelError, isTimeoutError, throwError } from "../error" | ||
@@ -223,3 +223,3 @@ // see https://github.com/microsoft/uf2/blob/main/hf2.md for full spec | ||
return this.lock.enqueue("talk", async () => { | ||
return this.enqueueTalk(async () => { | ||
if (!this.io) return null // disconnected | ||
@@ -230,2 +230,13 @@ return await this.sendMsgAsync(pkt).then(handleReturnAsync) | ||
private async enqueueTalk<T>(talk: () => Promise<T>): Promise<T> { | ||
try { | ||
if (!this.io) return undefined | ||
return this.lock.enqueue("talk", talk) | ||
} catch (e) { | ||
if (!this.io) return | ||
if (isCancelError(e)) return | ||
throw e | ||
} | ||
} | ||
private sendMsgAsync(buf: Uint8Array, serial = 0): Promise<void> { | ||
@@ -232,0 +243,0 @@ // Util.assert(buf.length <= this.maxMsgSize) |
@@ -26,3 +26,3 @@ import { Proto } from "./proto" | ||
import { jdpack } from "../pack" | ||
import { throwError } from "../error" | ||
import { isCancelError, throwError } from "../error" | ||
@@ -75,3 +75,3 @@ export class JdUsbProto implements Proto { | ||
const cmd = read16(fr, 14) | ||
this.io.log("processing frame: 0x" + cmd.toString(16)) | ||
this.io?.log("processing frame: 0x" + cmd.toString(16)) | ||
} | ||
@@ -272,7 +272,8 @@ | ||
} | ||
return this.lock.enqueue("talk", async () => { | ||
return this.enqueueTalk(async () => { | ||
for (let i = 0; i < 10; ++i) { | ||
this.io.log(`detect hf2 ${i}...`) | ||
await this.io.sendPacketAsync(frameToSend) | ||
this.io?.log(`detect hf2 ${i}...`) | ||
await this.io?.sendPacketAsync(frameToSend) | ||
await delay(50) | ||
if (!this.io) return | ||
if (this.hf2Resp == null) { | ||
@@ -295,2 +296,13 @@ if (this.isHF2) { | ||
private async enqueueTalk<T>(talk: () => Promise<T>): Promise<T> { | ||
try { | ||
if (!this.io) return undefined | ||
return this.lock.enqueue("talk", talk) | ||
} catch (e) { | ||
if (!this.io) return | ||
if (isCancelError(e)) return | ||
throw e | ||
} | ||
} | ||
onJDMessage(f: (buf: Uint8Array) => void) { | ||
@@ -300,5 +312,6 @@ this.frameHandler = f | ||
sendJDMessageAsync(fr: Uint8Array) { | ||
return this.lock.enqueue("talk", async () => { | ||
async sendJDMessageAsync(fr: Uint8Array) { | ||
this.enqueueTalk(async () => { | ||
for (const buf of this.encodeFrame(fr)) { | ||
if (!this.io) break | ||
await this.io.sendPacketAsync(buf) | ||
@@ -392,5 +405,6 @@ } | ||
if (this.numFrames > 0) break | ||
if (!this.io) break | ||
this.io.log(`waiting for response ${i}...`) | ||
} | ||
this.io.log("connected") | ||
this.io?.log("connected") | ||
} | ||
@@ -397,0 +411,0 @@ |
@@ -210,3 +210,3 @@ import { ERROR_TIMEOUT } from "./constants" | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
private readonly promises: SMap<(() => Promise<any>)[]> = {} | ||
private readonly promises: Record<string, (() => Promise<any>)[]> = {} | ||
@@ -213,0 +213,0 @@ enqueue<T>(id: string, f: () => Promise<T>): Promise<T> { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
46580826
216664