Skip to content

Commit 8a0c02a

Browse files
committed
util/promise: add promisify() helper
1 parent fb2bd6d commit 8a0c02a

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

ddterm/util/promise.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,21 @@
55
import GLib from 'gi://GLib';
66
import Gio from 'gi://Gio';
77

8+
export function promisify(start, finish) {
9+
return function (...args) {
10+
return new Promise((resolve, reject) => {
11+
// eslint-disable-next-line no-invalid-this
12+
start.call(this, ...args, (source, result) => {
13+
try {
14+
resolve(finish.call(source, result));
15+
} catch (error) {
16+
reject(error);
17+
}
18+
});
19+
});
20+
};
21+
}
22+
823
export async function wait_timeout(message, timeout_ms, cancellable = null) {
924
let source, cancel_handler;
1025

0 commit comments

Comments
 (0)