本文整理汇总了TypeScript中rxjs/Rx.Observable.fromPromise方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Observable.fromPromise方法的具体用法?TypeScript Observable.fromPromise怎么用?TypeScript Observable.fromPromise使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rxjs/Rx.Observable
的用法示例。
在下文中一共展示了Observable.fromPromise方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: findAndCount
/**
* Finds entities that match given conditions.
*/
findAndCount(conditionsOrFindOptions?: Object|FindOptions, options?: FindOptions): Rx.Observable<[ Entity[], number ]> {
if (conditionsOrFindOptions && options) {
return Rx.Observable.fromPromise(this.repository.findAndCount(conditionsOrFindOptions, options));
} else if (conditionsOrFindOptions) {
return Rx.Observable.fromPromise(this.repository.findAndCount(conditionsOrFindOptions));
} else {
return Rx.Observable.fromPromise(this.repository.findAndCount());
}
}
示例2: findOne
/**
* Finds first entity that matches given conditions.
*/
findOne(conditionsOrFindOptions?: Object|FindOptions, options?: FindOptions): Rx.Observable<Entity> {
if (conditionsOrFindOptions && options) {
return Rx.Observable.fromPromise(this.repository.findOne(conditionsOrFindOptions, options));
} else if (conditionsOrFindOptions) {
return Rx.Observable.fromPromise(this.repository.findOne(conditionsOrFindOptions));
} else {
return Rx.Observable.fromPromise(this.repository.findOne());
}
}
示例3: getTotalTasks
/**
* Return the total number of the tasks by filter
* @param requestNode - TaskFilterRepresentationModel
* @returns {any}
*/
public getTotalTasks(requestNode: TaskQueryRequestRepresentationModel): Observable<any> {
requestNode.size = 0;
return Observable.fromPromise(this.callApiTasksFiltered(requestNode))
.map((res: any) => {
return res;
}).catch(this.handleError);
}
示例4: validateTextDocumentAsync
export function validateTextDocumentAsync(textDocument: TextDocument, options: CSpellUserSettings): Rx.Observable<Diagnostic> {
const limit = (options.checkLimit || defaultCheckLimit) * 1024;
const text = textDocument.getText().slice(0, limit);
return Rx.Observable.fromPromise<cspell.TextOffset[]>(validateText(text, options))
.flatMap(a => a)
.filter(a => !!a)
.map(a => a!)
// Convert the offset into a position
.map(offsetWord => ({...offsetWord, position: textDocument.positionAt(offsetWord.offset) }))
// Calculate the range
.map(word => ({
...word,
range: {
start: word.position,
end: ({...word.position, character: word.position.character + word.text.length })
}
}))
// Convert it to a Diagnostic
.map(({text, range}) => ({
severity: DiagnosticSeverity.Information,
range: range,
message: `Unknown word: "${text}"`,
source: diagSource
}))
;
}
示例5: func
.catch(error => {
if (error.status === 401) {
this.authService.unauthenticated(); // 401 means authentication required
let message = this.authService.isOrgApiKeySet ? 'Incorrect organization API key' : 'Authentication is required';
return Observable.fromPromise(this.authService.login(message))
.mergeMap(confirmed => {
if (confirmed) { // logged in again, or updated api key
this.authService.authenticationMayChange();
switch (params.length) {
case 1:
return func(params[0]);
case 2:
return func(params[0], params[1]);
case 3:
return func(params[0], params[1], params[2]);
default:
return Observable.throw(new Error('Wrong number of parameters: ' + params));
}
}else { // canceled
return Observable.throw(new Error('User cancelled authentication'));
}
});
}else {
let errorDetail = error.json();
if (errorDetail) {
this.authService.authenticated(); // a valid API response received
return Observable.throw(new Error(errorDetail.type + ': ' + errorDetail.message));
}
console.log('API call failed: ' + JSON.stringify(error));
return Observable.throw(error);
}
});
示例6: addFilter
/**
* Add a filter
* @param filter - FilterRepresentationModel
* @returns {FilterRepresentationModel}
*/
addFilter(filter: FilterRepresentationModel): Observable<FilterRepresentationModel> {
return Observable.fromPromise(this.callApiAddFilter(filter))
.map(res => res)
.map((response: FilterRepresentationModel) => {
return response;
}).catch(this.handleError);
}
示例7: ngOnInit
ngOnInit() {
// Don't process restart for Rudi ("Rudi Rule")
let user = this.session.get().user;
if ( user && user.id == 10 ) {
this.router.navigate(['upload']);
return;
}
Observable.fromPromise(this.resume.resumeIsDone())
.ignoreElements() // make sure this doesn't emit values
.do(() => console.log('restarting session...'))
.concat(this.backend.resetSession())
.subscribe({
next: (res) => {
console.info('success restarting session', res.json());
let session = this.session.get();
// keep user and token data
this.session.reset( {user:session.user, token:session.token} );
this.router.navigate(['upload']);
},
error: (err) => {
console.log('error restarting session', err.json());
this.router.navigate(['upload']);
}
});
}
示例8: exportReportToCsv
exportReportToCsv(reportId: string, paramsQuery: any): Observable<any> {
return Observable.fromPromise(this.apiService.getInstance().activiti.reportApi.exportToCsv(reportId, paramsQuery))
.map((res: any) => {
this.logService.info('export');
return res;
}).catch(err => this.handleError(err));
}
示例9: getTaskDetails
/**
* Retrive all the task details
* @param id - taskId
* @returns {<TaskDetailsModel>}
*/
getTaskDetails(id: string): Observable<TaskDetailsModel> {
return Observable.fromPromise(this.callApiTaskDetails(id))
.map(res => res)
.map((details: any) => {
return new TaskDetailsModel(details);
}).catch(this.handleError);
}
示例10: createNewTask
/**
* Create a new standalone task
* @param task - TaskDetailsModel
* @returns {TaskDetailsModel}
*/
createNewTask(task: TaskDetailsModel): Observable<TaskDetailsModel> {
return Observable.fromPromise(this.callApiCreateTask(task))
.map(res => res)
.map((response: TaskDetailsModel) => {
return new TaskDetailsModel(response);
}).catch(this.handleError);
}