Puas yog kev cog lus async?
Puas yog kev cog lus async?

Video: Puas yog kev cog lus async?

Video: Puas yog kev cog lus async?
Video: Cog Lus Zaum Kawg Cover by Ab nplaim Lauj Ft Kab zuag Lis 2024, Hlis ntuj nqeg
Anonim

async functions siv ib tug implicit cog lus kom rov qab tau nws cov txiaj ntsig. Txawm hais tias koj tsis rov qab ib cog lus qhia meej async muaj nuj nqi ua kom paub tseeb tias koj tus lej dhau los ntawm a cog lus . tos tsuas yog thaiv cov cai ua tiav hauv lub async muaj nuj nqi. Nws tsuas yog ua kom paub tseeb tias kab tom ntej raug tua thaum lub cog lus daws.

Yog li ntawd, async puas rov qab cog lus?

Async functions Lo lus async ” ua ntej muaj nuj nqi txhais tau tias ib qho yooj yim tshaj plaws: ua haujlwm ib txwm rov qab cog lus . Lwm qhov tseem ceeb yog qhwv hauv qhov kev daws teeb meem cog lus txiav txim. Yog li ntawd, async xyuas kom meej tias muaj nuj nqi rov qab cog lus , thiab qhwv tsis tau- cog lus hauv nws.

Kuj Paub, Kuv yuav siv li cas async tos nrog cov lus cog tseg? Yog koj siv tus async lo lus tseem ceeb ua ntej lub luag haujlwm txhais, koj tuaj yeem ua tau siv tos hauv kev ua haujlwm. Thaum koj tos a cog lus , muaj nuj nqi yog paused nyob rau hauv ib tug tsis-blocking txoj kev mus txog rau thaum lub cog lus nyob. Yog tias cog lus ua tiav, koj tau txais tus nqi rov qab. Yog tias cog lus tsis lees paub, tus nqi tsis lees txais yog pov tseg.

Tsis tas li ntawd, Promise synchronous lossis asynchronous?

Kev cog lus tsis raws nraim synchronous los yog asynchronous hauv thiab ntawm lawv tus kheej. Thaum koj tsim ib cog lus lub callback koj dhau mus rau nws yog tam sim ntawd tua thiab tsis muaj lwm yam code yuav khiav mus txog rau thaum uas muaj nuj nqi yields.

async ua dab tsi?

Cov async function declaration txhais ib asynchronous muaj nuj nqi - muaj nuj nqi uas rov qab AsyncFunction khoom. Asynchronous functions ua hauj lwm nyob rau hauv ib tug nyias muaj nyias ib qhov kev txiav txim tshaj li tus so ntawm cov cai ntawm qhov kev tshwm sim voj, rov qab ib tug implicit Promise raws li nws tshwm sim.

Pom zoo: