当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript Observable.forkJoin方法代码示例

本文整理汇总了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();
       }
     );
 }
开发者ID:malaman,项目名称:other,代码行数:30,代码来源:pupulateDB.ts

示例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);
  }
);
开发者ID:relution-io,项目名称:relution-cli,代码行数:30,代码来源:cli.ts

示例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++) {
开发者ID:malaman,项目名称:other,代码行数:31,代码来源:pupulateDB.ts


注:本文中的@reactivex/rxjs.Observable.forkJoin方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。