本文整理汇总了TypeScript中rxjs/Subscription.Subscription.add方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Subscription.add方法的具体用法?TypeScript Subscription.add怎么用?TypeScript Subscription.add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rxjs/Subscription.Subscription
的用法示例。
在下文中一共展示了Subscription.add方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: loadData
private loadData() {
this.loadConfig();
this.loadOrder();
this.subscription.add(this.walletService.all().subscribe(wallets => {
this.wallets = wallets;
if (this.order) {
this.form.get('wallet').setValue(this.order.filename, { emitEvent: false });
}
}));
}
示例2: ngOnInit
ngOnInit() {
this.subscriptions = IntervalObservable
.create(5000)
.switchMap(() => this.blockchainService.lastBlock())
.subscribe(block => this.block = block);
this.subscriptions.add(IntervalObservable
.create(5000)
.switchMap(() => this.blockchainService.coinSupply())
.subscribe(coinSupply => this.coinSupply = coinSupply),
);
}
示例3: findActualExecutable
let spawnObs = Observable.create((subj: Observer<{
source: any,
text: any
}>) => {
let { cmd, args } = findActualExecutable(exe, params);
d(`spawning process: ${cmd} ${args.join()}, ${JSON.stringify(opts)}`);
let origOpts = assign({}, opts);
if ('jobber' in origOpts) {
delete origOpts.jobber;
}
if ('split' in origOpts) {
delete origOpts.split;
};
const proc = spawnOg(cmd, args, origOpts);
let bufHandler = (source: string) => (b: string | Buffer) => {
if (b.length < 1) {
return;
};
let chunk = '<< String sent back was too long >>';
try {
chunk = b.toString();
} catch (e) {
chunk = `<< Lost chunk of process output for ${exe} - length was ${b.length}>>`;
}
subj.next({ source: source, text: chunk });
};
let ret = new Subscription();
if (opts.stdin) {
if (proc.stdin) {
ret.add(opts.stdin.subscribe(
(x: any) => proc.stdin.write(x),
subj.error,
() => proc.stdin.end()
));
} else {
subj.error(new Error(`opts.stdio conflicts with provided spawn opts.stdin observable, 'pipe' is required`));
}
}
let stderrCompleted: Subject<boolean> | Observable<boolean> | null = null;
let stdoutCompleted: Subject<boolean> | Observable<boolean> | null = null;
let noClose = false;
if (proc.stdout) {
stdoutCompleted = new AsyncSubject<boolean>();
proc.stdout.on('data', bufHandler('stdout'));
proc.stdout.on('close', () => { (stdoutCompleted! as Subject<boolean>).next(true); (stdoutCompleted! as Subject<boolean>).complete(); });
} else {
stdoutCompleted = Observable.of(true);
}
if (proc.stderr) {
stderrCompleted = new AsyncSubject<boolean>();
proc.stderr.on('data', bufHandler('stderr'));
proc.stderr.on('close', () => { (stderrCompleted! as Subject<boolean>).next(true); (stderrCompleted! as Subject<boolean>).complete(); });
} else {
stderrCompleted = Observable.of(true);
}
proc.on('error', (e: Error) => {
noClose = true;
subj.error(e);
});
proc.on('close', (code: number) => {
noClose = true;
let pipesClosed = Observable.merge(stdoutCompleted!, stderrCompleted!)
.reduce((acc) => acc, true);
if (code === 0) {
pipesClosed.subscribe(() => subj.complete());
} else {
pipesClosed.subscribe(() => subj.error(new Error(`Failed with exit code: ${code}`)));
}
});
ret.add(new Subscription(() => {
if (noClose) {
return;
};
d(`Killing process: ${cmd} ${args.join()}`);
if (opts.jobber) {
// NB: Connecting to Jobber's named pipe will kill it
net.connect(`\\\\.\\pipe\\jobber-${proc.pid}`);
setTimeout(() => proc.kill(), 5 * 1000);
} else {
proc.kill();
}
}));
return ret;
});
示例4: addTo
export function addTo(collectorSub: Subscription): void {
collectorSub.add(this);
}