mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
34 lines
895 B
TypeScript
34 lines
895 B
TypeScript
/// <reference path="node.d.ts"/>
|
|
|
|
|
|
// TODO: extract services types
|
|
interface HostCancellationToken {
|
|
isCancellationRequested(): boolean;
|
|
}
|
|
|
|
const fs: typeof NodeJS.fs = require("fs");
|
|
|
|
function createCancellationToken(args: string[]): HostCancellationToken {
|
|
let cancellationPipeName: string;
|
|
for (let i = 0; i < args.length - 1; i++) {
|
|
if (args[i] === "--cancellationPipeName") {
|
|
cancellationPipeName = args[i + 1];
|
|
break;
|
|
}
|
|
}
|
|
if (!cancellationPipeName) {
|
|
return { isCancellationRequested: () => false };
|
|
}
|
|
return {
|
|
isCancellationRequested() {
|
|
try {
|
|
fs.statSync(cancellationPipeName);
|
|
return true;
|
|
}
|
|
catch(e) {
|
|
return false;
|
|
}
|
|
}
|
|
};
|
|
}
|
|
export = createCancellationToken |