Skip to content

Instantly share code, notes, and snippets.

@uliwitness
Created September 9, 2017 10:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save uliwitness/43baf6401f6f411a9493faa03bad563f to your computer and use it in GitHub Desktop.
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
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;
}
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