 
 # Object will emit change events *if* listen:true when creating it.
 class ClientSyncDB extends EventEmitter
-    constructor : (@string_id, @max_length, @listen, @session_id,
-                   @push_to_remote, @init_ver, @client) ->
-        @_register_listener()
+    constructor : (opts) ->
+        opts = defaults opts,
+            string_id      : required
+            max_length     : required
+            listen         : undefined
+            session_id     : undefined
+            push_to_remote : undefined
+            client         : required
+            cb             : required
+        @string_id      = opts.string_id
+        @max_length     = opts.max_length
+        @listen         = opts.listen
+        @session_id     = opts.session_id
+        @push_to_remote = opts.push_to_remote
+        @client         = opts.client
+        async.series([
+            (cb) =>
+                @_register_listener(cb)
+            (cb) =>
+                @_init_session(cb)
+        ], (err) =>
+            if err
+                opts.cb(err)
+            else
+                opts.cb(undefined, @)
+        )
 
     destroy : () =>
         @client._syncdb_destroy(string_id:@string_id)

        opts.string_id  = @string_id
        opts.max_length = @max_length
        @client._syncdb_call(opts)

    _register_listener: (cb) =>
        if not @listen

class SyncstringClient extends microservice.Client
    constructor: (opts) ->
        @_syncdb_cache = {}
        @_syncdb_cache_cbs = {}
        opts.name = "syncstring"
        @on("mesg_syncdb_change", @_syncdb_change)
        @on("mesg_push_to_remote", @_push_to_remote)
        @on('connect',@_syncdb_register_listeners)
        super(opts)

    # Synchronized database client: provides both syncdb api and also a
    # general diffsync api for clients that can do diffs/patches
    # (so can block for a fraction of a second or relay such patches).
    syncdb: (opts) =>
        opts = defaults opts,
            string_id      : required
