Skip to content
This repository has been archived by the owner on May 27, 2020. It is now read-only.

Commit

Permalink
feat: improve fetch module with progress
Browse files Browse the repository at this point in the history
  • Loading branch information
axetroy committed Feb 16, 2020
1 parent 5ad9851 commit 1eaeb41
Showing 1 changed file with 45 additions and 20 deletions.
65 changes: 45 additions & 20 deletions client/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -459,27 +459,52 @@ Executable ${this.denoInfo.executablePath}`;
text
);

const ps = execa(this.denoInfo.executablePath, [
"fetch",
remoteModuleUrl
]);

this.output.show();

ps.stdout.on("data", (buf: Buffer) =>
this.output.append(buf.toString())
);
ps.stderr.on("data", (buf: Buffer) =>
this.output.append(buf.toString())
await window.withProgress(
{
title: `Fetching`,
location: ProgressLocation.Notification,
cancellable: true
},
(process, cancelToken) => {
const ps = execa(
this.denoInfo.executablePath,
["fetch", remoteModuleUrl],
{
// timeout of 2 minute
timeout: 1000 * 60 * 2
}
);

const updateProgress = (buf: Buffer) => {
const raw = buf.toString();

const messages = raw.split("\n");

for (const message of messages) {
if (message) {
process.report({ message });
this.output.appendLine(message);
}
}
};

cancelToken.onCancellationRequested(ps.kill.bind(ps));

ps.stdout.on("data", updateProgress);
ps.stderr.on("data", updateProgress);

return new Promise((resolve, reject) => {
ps.on("exit", (code: number) => {
if (code !== 0 && !cancelToken.isCancellationRequested) {
this.output.show();
}
this.output.appendLine(`exit with code: ${code}`);
this.updateDiagnostic(editor.document.uri);
resolve();
});
});
}
);

await new Promise((resolve, reject) => {
ps.on("exit", (code: number) => {
this.output.appendLine(`exit with code: ${code}`);
this.updateDiagnostic(editor.document.uri);
resolve();
});
});
},
_create_local_module: async (editor, text) => {
const extName = path.extname(text);
Expand Down

0 comments on commit 1eaeb41

Please sign in to comment.