Dab tsi yog async muaj nuj nqi hauv Nodejs?
Dab tsi yog async muaj nuj nqi hauv Nodejs?

Video: Dab tsi yog async muaj nuj nqi hauv Nodejs?

Video: Dab tsi yog async muaj nuj nqi hauv Nodejs?
Video: Dab Tsi Hem 2024, Hlis ntuj nqeg
Anonim

async functions cia koj sau Promise -based code zoo li nws yog synchronous. Thaum koj txhais a muaj nuj nqi siv cov async lo lus tseem ceeb, ces koj tuaj yeem siv lub tos keyword nyob rau hauv muaj nuj nqi lub cev. Thaum lub async muaj nuj nqi rov qab tus nqi, Cov Lus Cog Tseg tau ua tiav, yog tias qhov async muaj nuj nqi pov ib qho yuam kev, nws tau txais tsis lees paub.

Kuj nug, dab tsi yog async tos hauv Nodejs?

Async / tos yog ib txoj kev tshiab sau asynchronous code. Cov kev xaiv yav dhau los rau asynchronous code yog callbacks thiab cog lus. Async / tos yog qhov tseeb xwb syntax qab zib ua rau saum cov lus cog tseg. Nws tsis tuaj yeem siv nrog cov callbacks dawb lossis node callbacks.

Qhov thib ob, dab tsi ua haujlwm async rov qab los? Cov async muaj nuj nqi tshaj tawm txhais ib asynchronous muaj nuj nqi , qho rov qab los ib AsyncFunction khoom. Thaum ib async muaj nuj nqi npe, it rov qab los Kev cog lus. Thaum lub async muaj nuj nqi rov qab tus nqi, Kev cog lus yuav raug daws nrog rau rov qab los tus nqi.

Tsis tas li ntawd, kev siv Async yog dab tsi?

Asynchronous programming yog ib daim ntawv ntawm parallel programming uas tso cai rau ib chav haujlwm ua haujlwm sib cais los ntawm thawj daim ntawv thov xov. Thaum ua haujlwm tiav, nws ceeb toom rau cov xov tseem ceeb (nrog rau seb qhov haujlwm puas tiav lossis ua tsis tiav).

Yuav ua li cas tos Async ua?

Cov tos lo lus tseem ceeb tsuas siv tau hauv async muaj nuj nqi. Lub hom phiaj ntawm async / tos yog kom yooj yim siv cov lus cog tseg synchronously, thiab ua qee tus cwj pwm ntawm ib pab pawg Cov Lus Cog Tseg. Raws li Cov Lus Cog Tseg zoo ib yam li cov qauv hu rov qab, async / tos zoo ib yam li kev sib txuas cov tshuab hluav taws xob thiab cov lus cog tseg.

Pom zoo: