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


TypeScript Observable.fromPromise方法代码示例

本文整理汇总了TypeScript中rxjs.Observable.fromPromise方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Observable.fromPromise方法的具体用法?TypeScript Observable.fromPromise怎么用?TypeScript Observable.fromPromise使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在rxjs.Observable的用法示例。


在下文中一共展示了Observable.fromPromise方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: factory

function createObservable<T>(factory: () => Promise<T>): Observable<T> {
  const topic: Promise<T> = factory();

  if (topic instanceof Promise) {
    const lazyRec: () => Observable<T> = () => {
      return Observable.fromPromise(factory()).concat(
          Observable.timer(60 * 60 * 1000).flatMap(() => lazyRec()));
    };

    return Observable.fromPromise(topic).concat(
        Observable.timer(60 * 60 * 1000).flatMap(() => lazyRec()));
  } else {
    return Observable.fromPromise(topic);
  }
}
开发者ID:blmarket,项目名称:simple-amd,代码行数:15,代码来源:factory-loader.ts

示例2: getProjectMembers

 getProjectMembers(projectId: string): Rx.Observable<Member[]> {
   const get = MemberModel.getProjectMembers(projectId)
   if (get) return get
   return Rx.Observable
     .fromPromise(memberFetch.getProjectMembers(projectId))
     .concatMap(x => MemberModel.saveProjectMembers(projectId, x))
 }
开发者ID:teambition,项目名称:TB-Linter,代码行数:7,代码来源:MemberAPI.ts

示例3:

 this.accounts$ = Observable.defer(() => {
   const promise = API.one('credentials')
     .useCache()
     .withParams({ expand: true })
     .get();
   return Observable.fromPromise<IAccountDetails[]>(promise);
 })
开发者ID:emjburns,项目名称:deck,代码行数:7,代码来源:AccountService.ts

示例4: connect

    public connect(): Observable<Channel> {
        if (!this._uri) {
            return Observable.throw(
                new Error('Uri must be defined in order to start connection')
            );
        }

        const self: RPC_Client = this;

        // Connect to RabbitMQ
        const connPromise: any = connect(this.uri)
            // Assign Connection and Create Channel
            .then((connection: Connection) => {
                self._connection = connection;
                return connection.createChannel();
            })

            // Assign Channel and create consume listener
            .then((channel: Channel) => {
                self._channel = channel;
                channel.setMaxListeners(0);

                // Action to take when message received
                self.consumeChannel.apply(self, [channel]);

                return channel;
            });

        return Observable.fromPromise(connPromise);
    }
开发者ID:db3dev,项目名称:amqp-rpc-client-controller,代码行数:30,代码来源:client.ts

示例5: addToIndex

 addToIndex(value): Observable<any> {
     var client = new elasticsearch.Client({
         host: 'http://localhost:9200',
         log: 'trace'
     });
     return Observable.fromPromise(client.create(value))
 }
开发者ID:cwdonnelly,项目名称:angular2-elastic,代码行数:7,代码来源:elasticsearch.service.ts

示例6: rpcPush

    public rpcPush(queueName: string, message: any): Observable<{content: any}> {
        if (!this.connection || !this.channel) {
            return Observable.throw(
                new Error('A connection is required to send messages.')
            );
        }

        if (typeof message !== 'object') {
            return Observable.throw(
                new Error('Message must be a JSON object.')
            );
        }

        const self: RPC_Client = this;

        return Observable.fromPromise<any>(
            new Promise(
                (resolve: Function) => {
                    // Generate message id
                    const correlationId: string = self.generateUuid();

                    // Create listener for response
                    self.responseEmitter.once(correlationId, resolve);

                    // Send message
                    self.sendMessageToQueue.apply(self, [queueName, message, correlationId]);
                }
            )
                .then((msg: Buffer) => JSON.parse(msg.toString()))
        );
    }
开发者ID:db3dev,项目名称:amqp-rpc-client-controller,代码行数:31,代码来源:client.ts

示例7: getTTSAccessToken

 // 百度TTS 合成token
 getTTSAccessToken()
 {
   let url = "https://openapi.baidu.com/oauth/2.0/token";
   let params = {
     "grant_type": "client_credentials",
     "client_id": "TPnGgO8zxIayL9iTTctlxqny",
     "client_secret": "820591dad6912546574487991d6bcb7d"
   };
   if(this.platform.is("cordova"))
   {
     return Observable.fromPromise(this.nativeHttp.get(url, params, {})).map((res:any) =>{
       return JSON.parse(res.data);
     }).catch(this.handleError);
   }
   else
   {
     url = url.replace("https:/", "");
     let searchParams = new URLSearchParams();
     for(let key in params)
     {
       searchParams.set(key, params[key]);
     }
     let reqOpts = new RequestOptions({"search": searchParams, "headers": new Headers()});
     return this.http.get(url, reqOpts).map(res=>{
       return res.json();
     }).catch(this.handleError);
   }
 }
开发者ID:qwb0920,项目名称:ionic2-GGDream,代码行数:29,代码来源:HttpClient.ts

示例8: it

it('Rx.Observable asynchronous test', function () {
  assert.strictEqual(count++, 10)
  return Rx.Observable.fromPromise(new Promise(function (resolve) {
    assert.strictEqual(count++, 11)
    setTimeout(resolve, 100)
  }))
})
开发者ID:thunks,项目名称:tman,代码行数:7,代码来源:simple.ts

示例9: execute

	execute() {
		if (this._watcher) {
			throw new Error('Already started');
		}

		return Observable.fromPromise(this.createAction())
			.flatMap(job => {
				if (this._runner === undefined) {
					const runner = new WatchExecutor(job, this._dialog);
					this._runner = runner;
					// FIXME how to stop the runner
					const cbk = _.debounce(path => runner.run(), this._debounceTime);
					this._watcher = chokidar.watch(this._def.files, {
						// ignored: /../,
						// persistent: true
					});
					this._watcher.on('error', err => {
						console.error('Error during watch', err);
					});
					this._watcher.on('ready', () => {
						LISTEN_EVENTS.forEach(eventName => this._watcher.on(eventName, cbk));
					});

					return runner.subject;
				} else {
					return this._runner.subject;
				}
			});
	}
开发者ID:Kineolyan,项目名称:Jarvis,代码行数:29,代码来源:WatchJob.ts

示例10: getOrgMembers

 getOrgMembers (organizationId: string): Rx.Observable<Member[]> {
   const get = MemberModel.getOrgMembers(organizationId)
   if (get) return get
   return Rx.Observable
     .fromPromise(memberFetch.getOrgMembers(organizationId))
     .concatMap(x => MemberModel.saveOrgMembers(organizationId, x))
 }
开发者ID:teambition,项目名称:TB-Linter,代码行数:7,代码来源:MemberAPI.ts


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