   task_create: (model, fn) =>
     id = @sync.create(TASK, model)
     @broadcast 'task.create', model
-    if type.function(fn) then fn(id)
+    if type.function(fn) then fn(null, id)
     return id
 
   list_create: (model, fn) =>
     id = @sync.create(LIST, model)
     @broadcast 'list.create', model
-    if type.function(fn) then fn(id)
+    if type.function(fn) then fn(null, id)
     return id
 
 

  task_update: (model, time, fn) =>
    model = @sync.update TASK, model, time
    if model then @broadcast 'task.update', model
    if type.function(fn) then fn()

  list_update: (model, time, fn) =>
    model = @sync.update LIST, model, time
    if model then @broadcast 'list.update', model
    if type.function(fn) then fn()

  pref_update: (model, time, fn) =>
    model = @sync.update PREF, model, time
    if model then @broadcast 'pref.update', model
    if type.function(fn) then fn()


  ###


class GuestSocket extends Socket

  events:
    user: ['auth']

  ###
   * GuestSocket
   *
   * This will handle a newly created socket and allow them to authenticate
   * themselves. There is a limited time to authenticate before the socket
   * will be automatically closed. This is done so that the server doesn't
   * have to handle any more sockets than it needs to.
   *
   * - socket (Jandal)
  ###

  constructor: (socket) ->
    super
    log 'A new guest has connected'
    @authenticated = false
    @authTimeout = setTimeout @timeout, TIMEOUT_AUTH


  ###
   * User Authentication
   *
   * The callback function will only be called if authentication is successful,
   * otherwise the socket will be instantly closed and an error message will be
   * sent back with it.
   *
   * - userId (int) : id of the user
   * - token (string) : login token
   * - fn (function) : callback
  ###

  user_auth: (@userId, token, fn) =>
    clearTimeout @authTimeout
