Skip to content

Commit

Permalink
Clean up use of bind
Browse files Browse the repository at this point in the history
  • Loading branch information
watson committed May 6, 2016
1 parent ddf4d05 commit 6f8e6be
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions lib/registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ function Registry (server) {

Registry.prototype.publish = function (opts) {
var service = new Service(opts)
service.start = start.bind(null, this, service)
service.stop = stop.bind(null, this, service)
service.start = start.bind(service, this)
service.stop = stop.bind(service, this)
service.start({ probe: opts.probe !== false })
return service
}
Expand All @@ -33,14 +33,15 @@ Registry.prototype.destroy = function () {
})
}

function start (registry, service, opts) {
if (service._activated) return
service._activated = true
function start (registry, opts) {
if (this._activated) return
this._activated = true

registry._services.push(service)
registry._services.push(this)

if (opts.probe) {
probe(registry._server.mdns, service, function (exists) {
var service = this
probe(registry._server.mdns, this, function (exists) {
if (exists) {
service.stop()
service.emit('error', new Error('Service name is already in use on the network'))
Expand All @@ -49,16 +50,16 @@ function start (registry, service, opts) {
announce(registry._server, service)
})
} else {
announce(registry._server, service)
announce(registry._server, this)
}
}

function stop (registry, service, cb) {
if (!service._activated) return // TODO: What about the callback?
function stop (registry, cb) {
if (!this._activated) return // TODO: What about the callback?

teardown(registry._server, service, cb)
teardown(registry._server, this, cb)

var index = registry._services.indexOf(service)
var index = registry._services.indexOf(this)
if (index !== -1) registry._services.splice(index, 1)
}

Expand Down

0 comments on commit 6f8e6be

Please sign in to comment.