當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。