INNER CODE UNIT · TypeScript
waitForBridgeResult
Dakkshin/after-effects-mcp · src/index.ts:78
async function waitForBridgeResult(expectedCommand?: string, timeoutMs: number = 5000, pollMs: number = 250): Promise<string> {
const start = Date.now();
const resultPath = path.join(getAETempDir(), 'ae_mcp_result.json');
let lastSize = -1;
while (Date.now() - start < timeoutMs) {
if (fs.existsSync(resultPath)) {
try {
const content = fs.readFileSync(resultPath, 'utf8');
if (content && content.length > 0 && content.length !== lastSize) {
lastSize = content.length;
try {
const parsed = JSON.parse(content);
if (!expectedCommand || parsed._commandExecuted === expectedCommand) {
return content;
}
} catch {
// not JSON yet; continue polling