Skip to content
This repository
Browse code

documented opts.wrap and opts.unwrap

  • Loading branch information...
commit 8608640823e314790e36c86899dba7b58bb402df 1 parent fb890b5
James Halliday authored

Showing 1 changed file with 6 additions and 6 deletions. Show diff stats Hide diff stats

  1. 12  README.markdown
12  README.markdown
Source Rendered
@@ -50,7 +50,7 @@ methods
50 50
 var protocol = require('dnode-protocol')
51 51
 ```
52 52
 
53  
-var proto = protocol(cons={}, wrap)
  53
+var proto = protocol(cons, opts={})
54 54
 -----------------------------------
55 55
 
56 56
 Create a new protocol object with a constructor `cons` and an optional callback
@@ -66,12 +66,12 @@ If you return an object in `cons` the return value will be used
66 66
 If you pass in a non-function as `cons`, its value will be used as the instance
67 67
 directly.
68 68
 
69  
-If specified, `wrap` gets called with `wrap(fn, id)` and should return the new
70  
-`fn` callback to use (it can be the same one).
  69
+You can optionally specify `opts.wrap` and `opts.unwrap` to wrap and unwrap
  70
+remote values for implementing weakmaps or marking callbacks.
71 71
 
72  
-`wrap` can be used to transform or mark callbacks before they are
73  
-inserted into the internal callacks.local hash. This is useful if you want to
74  
-implement weakrefs on top of dnode-protocol.
  72
+The return value of `opts.wrap(cb, id)` will be stored in `proto.callbacks.remote[id]`
  73
+and `opts.unwrap(ref, id)` will be called with the `ref` obtained from `wrap()`
  74
+previously to turn `ref` back into a `cb`.
75 75
 
76 76
 proto.handle(req)
77 77
 -----------------

0 notes on commit 8608640

Please sign in to comment.
Something went wrong with that request. Please try again.