本文整理汇总了TypeScript中@reactivex/rxjs.Observable.forkJoin方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Observable.forkJoin方法的具体用法?TypeScript Observable.forkJoin怎么用?TypeScript Observable.forkJoin使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类@reactivex/rxjs.Observable
的用法示例。
在下文中一共展示了Observable.forkJoin方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: Post
() => {
console.log('Users are saved!');
const postPromises = posts.map(post => {
const {userId, title, body} = post;
return User.findOne({id: userId})
.then(user => {
const newPost = new Post({title, body, _creator: user._id});
return newPost.save();
})
.then(newPost => {
const postCommentsIndex = i + 10;
for (i; i < postCommentsIndex && i < last; i++) {
const {body, email} = comments[i];
let newComment = new Comment({_post: newPost._id, body, email});
return newComment.save();
}
});
});
let counter = 0;
Rx.Observable
.forkJoin(postPromises)
.subscribe(
() => null,
(err) => console.log(`Err: ${err}`),
() => {
console.log('DB population is completed!');
process.exit();
}
);
}
示例2: Server
RelutionSDK.initFromArgs(argv);
// console.log('2', argv);
// all sub commands add to be here
const staticCommands: _.Dictionary<Command> = {
server: new Server(),
project: new Project(),
env: new Environment(),
connection: new Connection(),
push: new Push()
};
// observable to wait for before loading the tower some commands need a some data befor it can be initialised
const all = Object.keys(staticCommands).map((commandName: any) => {
return staticCommands[commandName].preload().defaultIfEmpty();
});
// preload done
Observable.forkJoin(all).subscribe(
(a: any) => {
// console.log(a);
},
(e: any) => {
console.error('preload', e);
process.exit(-1);
},
() => {
return new Tower(staticCommands, argv);
}
);
示例3: catch
try {
// conn.connection.collections['users'].drop();
// conn.connection.collections['posts'].drop();
// conn.connection.collections['comments'].drop();
} catch (e) {
console.log(`Error dropping tables: ${e}`);
}
// create user collection
const userPromises = users.map(user => {
const {id, username, name, email} = user;
const newUser = new User({id, username, name, email});
return newUser.save();
});
const userSource = Rx.Observable.forkJoin(userPromises);
const userSubscription = userSource.subscribe(
() => null,
(err) => console.log(`Err: ${err}`),
() => {
console.log('Users are saved!');
const postPromises = posts.map(post => {
const {userId, title, body} = post;
return User.findOne({id: userId})
.then(user => {
const newPost = new Post({title, body, _creator: user._id});
return newPost.save();
})
.then(newPost => {
const postCommentsIndex = i + 10;
for (i; i < postCommentsIndex && i < last; i++) {