Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions Backends/HTML5/kha/js/Microtask.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package kha.js;

import js.html.MessageChannel;

class Microtask {
static var messageChannel: MessageChannel;
static final callbacks: Array<() -> Void> = [];

static function init(): Void {
if (messageChannel != null) {
return;
}
messageChannel = new MessageChannel();
messageChannel.port1.onmessage = _ -> {
final copy = callbacks.copy();
callbacks.resize(0);
for (callback in copy) {
callback();
}
};
}

public static function queueMicrotask(callback: () -> Void): Void {
init();
callbacks.push(callback);
messageChannel.port2.postMessage(js.Lib.undefined);
}
}
6 changes: 3 additions & 3 deletions Backends/HTML5/kha/js/WebAudioSound.hx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import kha.audio2.Audio;
super();
this.offset = 0;
this.buffer = buffer;
this.startTime = Audio._context.currentTime;
this.startTime = Audio._context.currentTime;
this.source = Audio._context.createBufferSource();
this.source.buffer = this.buffer;
this.source.connect(Audio._context.destination);
Expand Down Expand Up @@ -91,7 +91,7 @@ class WebAudioSound extends kha.Sound {
var i = 0;
final lidx = len * 2;
function uncompressInner() {
var chk_len = idx + 11025;
var chk_len = idx + 44100;
var next_chk = chk_len > lidx ? lidx : chk_len;
while (idx < next_chk) {
uncompressedData[idx] = ch0[i];
Expand All @@ -100,7 +100,7 @@ class WebAudioSound extends kha.Sound {
++i;
}
if (idx < lidx)
js.Browser.window.setTimeout(uncompressInner, 0);
Microtask.queueMicrotask(uncompressInner);
else {
compressedData = null;
done();
Expand Down
Loading