socketio / socket.io

Realtime application framework (Node.JS server)
https://socket.io
MIT License
61.09k stars 10.11k forks source link

arity of callback #268

Closed weepy closed 13 years ago

weepy commented 13 years ago

hi -- there seems to be some check of the arity of the function callback function :

  // client
  socket.emit('world', 'data', function() {
    callback && callback.apply(o, arguments)
  })

throws an error on the server ( callback undefined ) , whereas :

  // client
  socket.emit('world', 'data', function(data) {
    callback && callback.apply(o, arguments)
  })

works ok --- why is this ?

dvv commented 13 years ago

I can't see difference in code chunks. please, update

weepy commented 13 years ago

durhhhhhh !

updated !

dvv commented 13 years ago

"Getting acknowledgements" in readme states that functions of length > 1 trigger manual acknowledgement, while of length . < 1 should fire automatic acknowlegdement.

BTW, where do you define callback?

weepy commented 13 years ago

ah - ok - missed that bit of the docs. callback is defined in an outer scope:

world.remote = function(o, method, args, fn) {
  var callback = fn && function(data) { fn.apply(o, arguments) }
  socket.emit('world', o.id, method, args, callback)
}

On Tue, Jun 21, 2011 at 11:54 AM, dvv < reply@reply.github.com>wrote:

"Getting acknowledgements" in readme states that functions of length > 1 trigger manual acknowledgement, while of length . < 1 should fire automatic acknowlegdement.

BTW, where do you define callback?

Reply to this email directly or view it on GitHub:

https://github.com/LearnBoost/Socket.IO-node/issues/268#issuecomment-1409393

dvv commented 13 years ago

Am sorry, but fn is defined? Just to be sure callback is really a Function ;)

weepy commented 13 years ago

idea is that if fn is not provided (hence undefined) then I don't want an ack.