Created
September 9, 2017 10:11
-
-
Save uliwitness/43baf6401f6f411a9493faa03bad563f to your computer and use it in GitHub Desktop.
Example of two equivalent programs as an illustration how you can transform coroutines into blocks. Pseudocode
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void main() | |
{ | |
int foo = rand(); | |
int result1 = await doSomethingAsync(foo); | |
printf( "Result 1: %d", result1 ); | |
int result2 = await doSomethingAsync(foo + 1); | |
printf( "Result 2: %d", result2 ); | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void main() | |
{ | |
int foo = rand(); | |
void (^doSomethingAsyncCompletion2)(int) = ^( int result2 ) | |
{ | |
printf( "Result 2: %d", result2 ); | |
} | |
void (^doSomethingAsyncCompletion)(int) = ^( int result1 ) | |
{ | |
printf( "Result 1: %d", result1 ); | |
doSomethingAsync(foo,doSomethingAsyncCompletion2); | |
} | |
doSomethingAsync(foo, doSomethingAsyncCompletion); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment