Dab tsi yog kev siv tos hauv node JS?
Dab tsi yog kev siv tos hauv node JS?

Video: Dab tsi yog kev siv tos hauv node JS?

Video: Dab tsi yog kev siv tos hauv node JS?
Video: Merging PDFs with Python! 2024, Kaum ib hlis
Anonim

Nrog Node v8, async/ tos feature twb officially dov tawm los ntawm lub Node los nrog Cov Lus Cog Tseg thiab ua haujlwm chaining. Cov haujlwm yuav tsum tsis txhob raug chained ib qho tom qab, yooj yim tos txoj haujlwm uas rov qab cog lus. Tab sis txoj haujlwm async yuav tsum tau tshaj tawm ua ntej tos muaj nuj nqi rov qab cog lus.

Hauv qhov no, koj yuav siv li cas tos?

Cov tos lo lus tseem ceeb Qhov no tuaj yeem muab tso rau hauv pem hauv ntej ntawm ib qho async cog lus-raws li kev ua haujlwm kom ncua koj cov cai ntawm kab ntawd kom txog thaum cov lus cog tseg ua tiav, tom qab ntawd rov qab cov txiaj ntsig tshwm sim. Nyob rau hauv lub meantime, lwm cov cai uas tej zaum yuav tos rau lub sij hawm los ua kom tiav tau ua li ntawd.

Tom qab ntawd, lo lus nug yog, dab tsi yog lub ntsiab lus ntawm async tos? Async / tos tso cai rau ua kom nyuaj asynchronous code zoo li yooj yim li synchronous ib. Nws ua rau kev sau ntawv asynchronous code enormously yooj yim dua. Raws li koj tau sau tseg hauv koj tus kheej cov lus nug, nws zoo li yog tias koj tau sau qhov sib txawv ntawm synchronous - tab sis nws yog qhov tseeb asynchronous.

Yog li ntawd, vim li cas peb siv async thiab tos hauv JavaScript?

Async / Tos tau tsim los ua kom yooj yim cov txheej txheem ntawm kev ua hauj lwm nrog thiab sau chained cog lus. Async functions rov qab cog lus. Yog tias qhov haujlwm cuam tshuam qhov yuam kev, Cov Lus Cog Tseg yuav raug tsis lees paub. Yog tias qhov ua haujlwm rov qab muaj nuj nqis, Kev cog lus yuav raug daws.

Yuav ua li cas tos async ua haujlwm?

JavaScript ES8 tau qhia async / tos uas ua rau txoj hauj lwm ntawm ua haujlwm Nrog Cov Lus Cog Tseg yooj yim dua. Ib async muaj nuj nqi yuav muaj ib tos kev qhia, uas nres qhov kev ua tiav ntawm kev ua haujlwm thiab tos rau qhov kev cog lus dhau los qhov kev daws teeb meem, thiab tom qab ntawd rov pib dua async function's execution thiab xa rov qab tus nqi daws.

Pom zoo: