本文整理汇总了TypeScript中@reactivex/rxjs.Observable.subscribe方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Observable.subscribe方法的具体用法?TypeScript Observable.subscribe怎么用?TypeScript Observable.subscribe使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类@reactivex/rxjs.Observable
的用法示例。
在下文中一共展示了Observable.subscribe方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: to
to(exchange: string, iO: Observable<any>): Subscription<any> {
let channel, conn, cachedItems = [];
let queue = uuid.v4();
connect(this.config.connString)
.then(c => conn = c && c.createChannel())
.then(c => {
channel = c;
channel.assertExchange(exchange, 'fanout');
cachedItems.forEach(item => {
channel.publish(exchange, '', new Buffer(item));
});
})
.catch(err => { throw err; });
return iO
.subscribe(
msg => {
if (!channel) {
return cachedItems.push(msg);
}
channel.publish(exchange, '', new Buffer(msg));
},
err => console.error(`rabbitSink err, queue: ${queue}`, err),
() => {
if (conn) {
channel.publish(exchange, '', new Buffer('__done'));
conn.close()
}
}
);
}
示例2: httpDriver
export function httpDriver(input$: Observable<any>, options?: RequestInit): Subject<any> {
const result = new Subject();
input$.subscribe((url: string) => {
fetch(url, options).then(i => {
result.next(i);
});
});
return result;
};
示例3: to
to(channelName: string, iO: Observable<any>): Subscription<any> {
this.initChannel(channelName);
return iO.subscribe(
item => this.channels[channelName].forEach(fn => fn(item)),
err => { throw err; },
() => this.channels[channelName].forEach(fn => fn('__done'))
);
}
示例4: to
to(channelName: string, iO: Observable<any>): Subscription<any> {
let client = this.getClient();
return iO.subscribe(
item => {
if (typeof item !== 'string') {
item = JSON.stringify(item);
}
client.publish(channelName, item);
},
err => { throw err; },
() => client.publish(channelName, '__done')
);
}