javascript - Typescript async/await with Observable Or Promise -


can use async await this? killing async/await here? code below working without error, know async/await works promise<t>. getitem observable. thanks.

roleservice.getitem({ page: p.pageindex + 1, pagesize: p.pagesize }) .takeuntil(this.unsubscribe$) .map((res: responsedto) => <dtomodel>res.contentbody) .do(async (dto: dtomodel) => await this.subject.next(dto.content)) // working wihtout error .subscribe(async (dto: dtomodel) => await (this.pager = dto.pager), //working without error           (error: any) => observable.throw(error)); 

you can use async functions way have no effect in example. have understand async function returns promise:

const fn = async function() {}; fn() instanceof promise 

so if use in observable chain receive promise:

interval(500)   .first()   .map(async (v) => {     return v;   })   .subscribe((v) => {     console.log(v instanceof promise); // logs `true`   }); 

the way constructed example won't have effect on observables chain because output do operator ignored , there's no listener output subscribe callback. there's no reason use async there.

if wanted instead wait until async function resolves , results of function use mergemap operator:

interval(500)   .first()   .map(async (v) => {     return v;   })   .mergemap((p) => {     return p;   })   .subscribe((v) => {     console.log(v);   }); 

Comments

Popular posts from this blog

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -