本文整理汇总了TypeScript中@phosphor/signaling.ISignal类的典型用法代码示例。如果您正苦于以下问题:TypeScript ISignal类的具体用法?TypeScript ISignal怎么用?TypeScript ISignal使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ISignal类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: slot
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;
}
示例3: cleanup
function cleanup() {
signal.disconnect(slot);
}