javascript: queued connect/disconnect call handling