Skip to content

Commit 0a3a1c3

Browse files
committed
Update tasks.ts
1 parent 4def102 commit 0a3a1c3

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/resources/tasks.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
type TaskViewWithSchema,
1414
} from '../lib/parse';
1515
import { getTaskViewHash } from '../lib/stream';
16+
import { ExhaustiveSwitchCheck } from '../lib/types';
1617

1718
export class Tasks extends APIResource {
1819
/**
@@ -148,11 +149,17 @@ export class Tasks extends APIResource {
148149
yield { event: 'status', data: res };
149150
}
150151

151-
if (res.status === 'finished') {
152-
break poll;
152+
switch (res.status) {
153+
case 'finished':
154+
case 'stopped':
155+
case 'paused':
156+
break poll;
157+
case 'started':
158+
await new Promise((resolve) => setTimeout(resolve, config.interval));
159+
break;
160+
default:
161+
throw new ExhaustiveSwitchCheck(res.status);
153162
}
154-
155-
await new Promise((resolve) => setTimeout(resolve, config.interval));
156163
} while (true);
157164
}
158165

0 commit comments

Comments
 (0)