Skip to content

Commit

Permalink
Once and for all fixing this errno-transfer issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Yahweasel committed Sep 28, 2024
1 parent da59e81 commit f5841ad
Showing 1 changed file with 22 additions and 21 deletions.
43 changes: 22 additions & 21 deletions extern-post.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,41 +48,42 @@ if (/* We're in a worker */
var fun = e.data[1];
var args = e.data.slice(2);
var ret = void 0;
var transfer = [];
var succ = true;

function reply() {
var transfer = [];
if (ret && ret.libavjsTransfer)
transfer = ret.libavjsTransfer
try {
postMessage([id, fun, succ, ret], transfer);
} catch (ex) {
try {
ret = JSON.parse(JSON.stringify(
ret, function(k, v) { return v; }
));
postMessage([id, fun, succ, ret], transfer);
} catch (ex) {
postMessage([id, fun, succ, "" + ret]);
}
}
}

try {
ret = libav[fun].apply(libav, args);
} catch (ex) {
succ = false;
ret = ex;
}
if (succ && typeof ret === "object" && ret !== null && ret.then) {
if (succ && ret && ret.then) {
// Let the promise resolve
ret.then(function(res) {
ret = res;
}).catch(function(ex) {
succ = false;
ret = ex;
}).then(function() {
if (typeof ret === "object" && ret && ret.libavjsTransfer)
transfer = ret.libavjsTransfer;
try {
postMessage([id, fun, succ, ret], transfer);
} catch (ex) {
postMessage([id, fun, succ, "" + ret]);
}
});
}).then(reply);

} else {
if (typeof ret === "object" && ret && ret.libavjsTransfer)
transfer = ret.libavjsTransfer;
try {
postMessage([id, fun, succ, ret], transfer);
} catch (ex) {
postMessage([id, fun, succ, "" + ret]);
}

}
} else reply();
};

libav.onwrite = function(name, pos, buf) {
Expand Down

0 comments on commit f5841ad

Please sign in to comment.