Skip to content

Commit

Permalink
chore(xsnap): resolve floating-promise warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
toliaqat committed Aug 28, 2023
1 parent 6439256 commit f5fb0ce
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
13 changes: 8 additions & 5 deletions packages/xsnap/src/xsnap.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ export async function xsnap(options) {
sourceStream.pipe(destStream, { end: false });

done = finished(sourceStream);
done.catch(noop).then(() => sourceStream.unpipe(destStream));
void done.catch(noop).then(() => sourceStream.unpipe(destStream));
};

return harden({
Expand Down Expand Up @@ -258,7 +258,7 @@ export async function xsnap(options) {
await loadSnapshotHandler?.afterSpawn(snapshotLoadStream);

if (loadSnapshotHandler) {
vatExit.promise.catch(noop).then(() => {
void vatExit.promise.catch(noop).then(() => {
if (loadSnapshotHandler) {
const { cleanup } = loadSnapshotHandler;
loadSnapshotHandler = undefined;
Expand Down Expand Up @@ -458,10 +458,13 @@ export async function xsnap(options) {
const handle = await fs.open(snapPath, 'w+');
// @ts-expect-error 'close' event added in Node 15.4
handle.on('close', () => {
fs.unlink(snapPath);
// Safe to ignore the result because we are skipping to to clean up the temp directory.
void fs.unlink(snapPath);
});
sourceStream = handle.createReadStream();
finished(output).finally(() => sourceStream.destroy());
finished(output)
.finally(() => sourceStream.destroy())
.catch(noop);
} else {
sourceStream = snapshotSaveStream;
snapPath = `@${SNAPSHOT_SAVE_FD}`;
Expand All @@ -470,7 +473,7 @@ export async function xsnap(options) {
// ensuring that any previous save stream usage has ended. However we
// must start the flow before receiving the command's response or the
// xsnap process would block on a full pipe, causing an IPC deadlock.
batonKit.promise.then(maybePipe);
batonKit.promise.then(maybePipe, noop);
}

const cleanup = () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/xsnap/src/xsrepl.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,4 @@ async function main() {
return vat.close();
}

main();
await main().catch(err => console.log(err));
2 changes: 1 addition & 1 deletion packages/xsnap/test/fixture-xsnap-script.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint @typescript-eslint/no-floating-promises: "warn" */
/* global issueCommand */
(async () => {
void (async () => {
issueCommand(new TextEncoder().encode('Hello, World!').buffer);
})();

0 comments on commit f5fb0ce

Please sign in to comment.