Skip to content

Commit

Permalink
Merge pull request #482 from servusdei2018/main
Browse files Browse the repository at this point in the history
bumble.js(PacketSink): Implement asynchronous packet processing
  • Loading branch information
barbibulle committed May 9, 2024
2 parents 593c619 + 851d62c commit 22eb405
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions web/bumble.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,36 @@ class PacketSource {
}

class PacketSink {
constructor() {
this.queue = [];
this.isProcessing = false;
}

on_packet(packet) {
if (!this.writer) {
return;
}
const buffer = packet.toJs({create_proxies : false});
packet.destroy();
//console.log(`HCI[host->controller]: ${bufferToHex(buffer)}`);
// TODO: create an async queue here instead of blindly calling write without awaiting
this.writer(buffer);
this.queue.push(buffer);
this.processQueue();
}

async processQueue() {
if (this.isProcessing) {
return;
}
this.isProcessing = true;
while (this.queue.length > 0) {
const buffer = this.queue.shift();
await this.writer(buffer);
}
this.isProcessing = false;
}
}


class LogEvent extends Event {
constructor(message) {
super('log');
Expand Down Expand Up @@ -185,4 +203,4 @@ export async function setupSimpleApp(appUrl, bumbleControls, log) {
bumbleControls.onBumbleLoaded();

return app;
}
}

0 comments on commit 22eb405

Please sign in to comment.