mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-15 01:49:20 +02:00
fcl-passrc: allow external class function async
git-svn-id: trunk@45518 -
This commit is contained in:
parent
b6e2a228d3
commit
683c5c8faf
@ -6839,7 +6839,7 @@ begin
|
|||||||
RaiseMsg(20170216151616,nInvalidXModifierY,
|
RaiseMsg(20170216151616,nInvalidXModifierY,
|
||||||
sInvalidXModifierY,[GetElementTypeName(Proc),'external, '+ModifierNames[pm]],Proc);
|
sInvalidXModifierY,[GetElementTypeName(Proc),'external, '+ModifierNames[pm]],Proc);
|
||||||
for ptm in Proc.ProcType.Modifiers do
|
for ptm in Proc.ProcType.Modifiers do
|
||||||
if not (ptm in [ptmOfObject,ptmIsNested,ptmStatic,ptmVarargs,ptmReferenceTo]) then
|
if not (ptm in [ptmOfObject,ptmIsNested,ptmStatic,ptmVarargs,ptmReferenceTo,ptmAsync]) then
|
||||||
RaiseMsg(20170411171224,nInvalidXModifierY,
|
RaiseMsg(20170411171224,nInvalidXModifierY,
|
||||||
sInvalidXModifierY,[GetElementTypeName(Proc),'external, '+ProcTypeModifiers[ptm]],Proc);
|
sInvalidXModifierY,[GetElementTypeName(Proc),'external, '+ProcTypeModifiers[ptm]],Proc);
|
||||||
end;
|
end;
|
||||||
|
@ -2994,14 +2994,15 @@ End.
|
|||||||
|
|
||||||
<div class="section">
|
<div class="section">
|
||||||
<h2 id="async">Async/AWait</h2>
|
<h2 id="async">Async/AWait</h2>
|
||||||
Pas2js supports the JS operators async/await to simplify the use of Promise.
|
Pas2js supports the JS operators async and await to simplify the use of Promise.
|
||||||
The await operator corresponds to two intrinsic Pas2js functions:
|
The await operator corresponds to three intrinsic Pas2js functions:
|
||||||
<ul>
|
<ul>
|
||||||
<li><i>function await(const Expr: T): T;</i> // implicit promise</li>
|
<li><i>function await(AsyncFunctionWithResultT): T;</i> // implicit promise</li>
|
||||||
<li><i>function await(aType; p: TJSPromise): aType;</i> // explicit promise requires the resolved type</li>
|
<li><i>function await(aType; p: TJSPromise): aType;</i> // explicit promise requires the resolved type</li>
|
||||||
|
<li><i>function await(const Expr: T): T;</i> // implicit promise</li>
|
||||||
</ul>
|
</ul>
|
||||||
The await function can only be used inside a procedure with the async modifier.<br>
|
The await function can only be used inside a procedure with the async modifier.<br>
|
||||||
For example:
|
Example for the explicit promise:
|
||||||
<table class="sample">
|
<table class="sample">
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr>
|
<tr>
|
||||||
@ -3030,7 +3031,7 @@ procedure AsyncCall; async;
|
|||||||
var s: string;
|
var s: string;
|
||||||
begin
|
begin
|
||||||
writeln('calling');
|
writeln('calling');
|
||||||
s := await(string,resolveAfter2Seconds());
|
s := await(string,resolveAfter2Seconds()); // does not check if result is really a string
|
||||||
writeln(s); // expected output: 'resolved'
|
writeln(s); // expected output: 'resolved'
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -3067,6 +3068,11 @@ end.
|
|||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
Notes:
|
||||||
|
<ul>
|
||||||
|
<li>The await function does only compile time checks, no runtime checks.</li>
|
||||||
|
<li></li>
|
||||||
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user