Skip to content

Commit 2610148

Browse files
committed
await
1 parent 794cc8b commit 2610148

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

lib/functions/await.d.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { ITask } from "../types";
2+
/**
3+
* Returns an Promise which will resolve when the condition is satisfied, or rejected if timeout expired
4+
* @param condition Task which should resolve with check result
5+
* @param delay Delay between when condition task return value and run new one
6+
* @param timeout Timeout before promise will rejected. `-1` for endless waiting.
7+
* @returns Promise
8+
*/
9+
export declare function await(condition: ITask, delay: number, timeout?: number): Promise<any>;

lib/functions/await.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
"use strict";
2+
var prow = require("../prow");
3+
/**
4+
* Returns an Promise which will resolve when the condition is satisfied, or rejected if timeout expired
5+
* @param condition Task which should resolve with check result
6+
* @param delay Delay between when condition task return value and run new one
7+
* @param timeout Timeout before promise will rejected. `-1` for endless waiting.
8+
* @returns Promise
9+
*/
10+
function await(condition, delay, timeout) {
11+
if (timeout === void 0) { timeout = -1; }
12+
return new Promise(function (resolve, reject) {
13+
var conditionHandler = function (result) {
14+
if (result) {
15+
resolve();
16+
}
17+
};
18+
prow.retry(condition, -1, delay, timeout).then(conditionHandler).catch(reject);
19+
});
20+
}
21+
exports.await = await;

0 commit comments

Comments
 (0)