C# Language Specification


Classification of await expressions



Download 0,75 Mb.
bet239/524
Sana06.01.2022
Hajmi0,75 Mb.
#324842
1   ...   235   236   237   238   239   240   241   242   ...   524
Bog'liq
CSharp Language Specification

Classification of await expressions


The expression await t is classified the same way as the expression (t).GetAwaiter().GetResult(). Thus, if the return type of GetResult is void, the await-expression is classified as nothing. If it has a non-void return type T, the await-expression is classified as a value of type T.
        1. Runtime evaluation of await expressions


At runtime, the expression await t is evaluated as follows:

  • An awaiter a is obtained by evaluating the expression (t).GetAwaiter().

  • A bool b is obtained by evaluating the expression (a).IsCompleted.

  • If b is false then evaluation depends on whether a implements the interface System.Runtime.CompilerServices.ICriticalNotifyCompletion (hereafter known as ICriticalNotifyCompletion for brevity). This check is done at binding time; i.e. at runtime if a has the compile time type dynamic, and at compile time otherwise. Let r denote the resumption delegate (§Error: Reference source not found):

  • If a does not implement ICriticalNotifyCompletion, then the expression
    (a as (INotifyCompletion)).OnCompleted(r) is evaluated.

  • If a does implement ICriticalNotifyCompletion, then the expression
    (a as (ICriticalNotifyCompletion)).UnsafeOnCompleted(r) is evaluated.

  • Evaluation is then suspended, and control is returned to the current caller of the async function.

  • Either immediately after (if b was true), or upon later invocation of the resumption delegate (if b was false), the expression (a).GetResult() is evaluated. If it returns a value, that value is the result of the await-expression. Otherwise the result is nothing.

An awaiter’s implementation of the interface methods INotifyCompletion.OnCompleted and ICriticalNotifyCompletion.UnsafeOnCompleted should cause the delegate r to be invoked at most once. Otherwise, the behavior of the enclosing async function is undefined.

    1. Download 0,75 Mb.

      Do'stlaringiz bilan baham:
1   ...   235   236   237   238   239   240   241   242   ...   524




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish