Reducing number of awaits for speed
This commit is contained in:
14
src/index.ts
14
src/index.ts
@@ -211,7 +211,7 @@ export default class Updater {
|
||||
let packet = this.file.slice(this._fileProgress, this._fileProgress+this._packetSize);
|
||||
this._fileProgress += this._packetSize;
|
||||
return new Promise((resolve, reject) => {
|
||||
this.bleObject.write(this.bleDeviceId, this._updaterServiceUUID, this._updateFileCharacteristicUUID, packet.buffer,
|
||||
this.bleObject.writeWithoutResponse(this.bleDeviceId, this._updaterServiceUUID, this._updateFileCharacteristicUUID, packet.buffer,
|
||||
() => {
|
||||
resolve(true);
|
||||
},
|
||||
@@ -239,15 +239,15 @@ export default class Updater {
|
||||
// check for error
|
||||
|
||||
// write file length
|
||||
return new Promise(async (resolve, reject) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
// start notify
|
||||
this.bleObject.startNotification(this.bleDeviceId, this._updaterServiceUUID, this._updaterCommandCharacterisitcUUID,
|
||||
async (rawData: ArrayBuffer): Promise<void> => {
|
||||
(rawData: ArrayBuffer): void => {
|
||||
let dataView = new Uint8Array(rawData);
|
||||
console.log(dataView);
|
||||
if (dataView[0] == 1) {
|
||||
// send file
|
||||
await this.sendNextPacket();
|
||||
this.sendNextPacket();
|
||||
progressCallback(`Sending (${Math.floor((this._fileProgress *100)/this._fileSize)}%), ${this._fileProgress} / ${this._fileSize}`);
|
||||
} else if (dataView[0] == 2) {
|
||||
// done logic
|
||||
@@ -255,7 +255,7 @@ export default class Updater {
|
||||
if (this._fileProgress >= this._fileSize) {
|
||||
console.log("true");
|
||||
// send agree
|
||||
await this.sendEndCmd(true);
|
||||
this.sendEndCmd(true);
|
||||
progressCallback(`Complete!`);
|
||||
this.bleObject.stopNotification(this.bleDeviceId,
|
||||
this._updaterServiceUUID, this._updaterCommandCharacterisitcUUID,
|
||||
@@ -270,7 +270,7 @@ export default class Updater {
|
||||
} else {
|
||||
console.log("False");
|
||||
// send disagree
|
||||
await this.sendEndCmd(false);
|
||||
this.sendEndCmd(false);
|
||||
progressCallback(`Error, starting over: ${this._fileProgress} / ${this._fileSize}`);
|
||||
this._fileProgress = 0;
|
||||
}
|
||||
@@ -294,7 +294,7 @@ export default class Updater {
|
||||
const buffer = new ArrayBuffer(4)
|
||||
let view = new Int32Array(buffer);
|
||||
view[0] = this._fileSize;
|
||||
await this.bleObject.withPromises.write(this.bleDeviceId, this._updaterServiceUUID, this._updaterCommandCharacterisitcUUID, buffer);
|
||||
this.bleObject.withPromises.write(this.bleDeviceId, this._updaterServiceUUID, this._updaterCommandCharacterisitcUUID, buffer);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user