File tree Expand file tree Collapse file tree 1 file changed +24
-1
lines changed Expand file tree Collapse file tree 1 file changed +24
-1
lines changed Original file line number Diff line number Diff line change @@ -734,7 +734,30 @@ of the program to fork in two different threads of execution.
734734
735735` ` ` js
736736async loadImage (n: String ): Promise < ? > {
737- return await ImageIO .read (n);
737+ if (! cache .contains (n)) {
738+ return await ImageIO .read (n);
739+ }
740+ return cache .get (n); // no need to go async
741+ }
742+ ` ` `
743+
744+ All async functions can cascade such that if an async function calls another it is suspended until the function
745+ being called completes, at which point it will resume from the call site. For convenience closures can also
746+ be asynchronous.
747+
748+ ` ` ` js
749+ let loadImage = async (n: String ) - > ImageIO .read (n);
750+ ` ` `
751+
752+ Here there is no need to specify the await keyword as expression based asynchronous closures have an implicit await.
753+ For closures that have more than a single expression you must specify which statements are asynchronous.
754+
755+ ` ` ` js
756+ let loadImage = async (n: String ) - > {
757+ if (! cache .contains (n)) {
758+ return await ImageIO .read (n);
759+ }
760+ return cache .get (n); // no need to go async
738761}
739762` ` `
740763
You can’t perform that action at this time.
0 commit comments