Skip to content

Instantly share code, notes, and snippets.

@bithavoc
Created July 27, 2013 18:50
Show Gist options
  • Select an option

  • Save bithavoc/6095868 to your computer and use it in GitHub Desktop.

Select an option

Save bithavoc/6095868 to your computer and use it in GitHub Desktop.
example_stream_read
Duv takes the delegated passed to runMainDuv and wraps in a Fiber so we can suspend the execution while we wait for libuv.
here:
https://github.com/heapsource/duv/blob/master/src/duv/core.d#L159
Loops starts here, we block the execution of the app until the main fiber finishes:
https://github.com/heapsource/duv/blob/master/src/duv/core.d#L141
Example stream read:
1. Store the current fiber in the current stream object:
https://github.com/heapsource/duv/blob/master/src/duv/core.d#L534
2. Set the continuation delegate to resume the current fiber:
https://github.com/heapsource/duv/blob/master/src/duv/core.d#L540
3. Make sure when the libuv call the corresponding fiber resumes:
https://github.com/heapsource/duv/blob/master/src/duv/core.d#L545
4. Call uv_read_start
https://github.com/heapsource/duv/blob/master/src/duv/core.d#L547
We pass D's this.ptr as "data" pointer and a function pointer ready to drive the execution back to our Dobject:
https://github.com/heapsource/duv/blob/master/src/duv/core.d#L74
5. Cast back the object out of the "data" pointer and drive the execution back to our D object.
https://github.com/heapsource/duv/blob/master/src/duv/core.d#L82
6. Check for errors
https://github.com/heapsource/duv/blob/master/src/duv/core.d#L506
7. Drive the execution to our callback delegate (Step 2)
https://github.com/heapsource/duv/blob/master/src/duv/core.d#L514
and finally resuming resuming the fiber we left off before invoking libuv's async:
https://github.com/heapsource/duv/blob/master/src/duv/core.d#L545
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment