本文整理匯總了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')
);
}