本文整理汇总了TypeScript中@phosphor/signaling.ISignal.connect方法的典型用法代码示例。如果您正苦于以下问题:TypeScript ISignal.connect方法的具体用法?TypeScript ISignal.connect怎么用?TypeScript ISignal.connect使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类@phosphor/signaling.ISignal
的用法示例。
在下文中一共展示了ISignal.connect方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: Array
export function signalToPromises<T, U>(
signal: ISignal<T, U>,
numberValues: number
): Promise<[T, U]>[] {
const values: Promise<[T, U]>[] = new Array(numberValues);
const resolvers: Array<(value: [T, U]) => void> = new Array(numberValues);
for (let i = 0; i < numberValues; i++) {
values[i] = new Promise<[T, U]>(resolve => {
resolvers[i] = resolve;
});
}
let current = 0;
function slot(sender: T, args: U) {
resolvers[current++]([sender, args]);
if (current === numberValues) {
cleanup();
}
}
signal.connect(slot);
function cleanup() {
signal.disconnect(slot);
}
return values;
}
示例2: catch
export function testEmission<T, U, V>(
signal: ISignal<T, U>,
options: {
find?: (a: T, b: U) => boolean;
test?: (a: T, b: U) => void;
value?: V;
}
): Promise<V> {
const done = new PromiseDelegate<V>();
const object = {};
signal.connect((sender: T, args: U) => {
if (!options.find || options.find(sender, args)) {
try {
Signal.disconnectReceiver(object);
if (options.test) {
options.test(sender, args);
}
} catch (e) {
done.reject(e);
}
done.resolve(options.value || undefined);
}
}, object);
return done.promise;
}