Permalink
Browse files

Add async code to slides and async notes

  • Loading branch information...
nikhilm committed Jan 20, 2012
1 parent 32818f3 commit 3c769329e2c0ed365a1227d6c881177e47874859
Showing with 70 additions and 0 deletions.
  1. +70 −0 slides.rst
View
@@ -316,6 +316,76 @@ Unwrapping
Going Async
-----------
+* The easiest way is to use `uv_queue_work()`
+* Every async call requires a set of 3 functions
+ 1. Set up and invoke `uv_queue_work()`
+ 2. Do blocking task (run in separate thread)
+ 3. Clean up (run in main thread)
+* Use a 'baton' to pass around data
+ * `uv_request_t` is used by `libuv`
+ * But it's `data` field is important to store the baton itself
+* Slightly cumbersome :(
+
+Going Async
+-----------
+
+.. code-block:: js
+ :include: async/test.js
+
+Going Async
+-----------
+
+The native blocking code (method of class `Library::Inventory`)
+
+.. code-block:: cpp
+ :include: async/main.cc
+ :start-at: void reshelve
+ :end-at: }
+
+Going Async
+-----------
+
+JS callback
+
+.. code-block:: cpp
+ :include: async/main.cc
+ :start-at: static Handle<Value> Reshelve
+ :end-at: }
+
+Going Async
+-----------
+
+Thread pool function
+
+.. code-block:: cpp
+ :include: async/main.cc
+ :start-at: static void ReshelveAsync
+ :end-at: }
+
+Going Async
+-----------
+
+Clean up
+
+.. code-block:: cpp
+ :include: async/main.cc
+ :start-at: static void ReshelveAsyncAfter
+ :end-before: private
+
+Going Async
+-----------
+
+Output
+
+.. code-block:: txt
+
+ After reshelve in source
+ Tick
+ Tick
+ Tick
+ Tick
+ Reshelving done
+
Linking your library
--------------------

0 comments on commit 3c76932

Please sign in to comment.