Skip to content

Commit

Permalink
close server when reference URL is not defined
Browse files Browse the repository at this point in the history
  • Loading branch information
piranna committed Jan 25, 2016
1 parent b85ca7d commit 1b10c9e
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions lib/SubscribeContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ function SubscribeContext(options)
var port = options.port || 0
var hostname = options.hostname || '0.0.0.0'

createServer(function(req, res)
var server = createServer(function(req, res)
{
req.pipe(concat(function(body)
{
Expand All @@ -184,11 +184,15 @@ function SubscribeContext(options)
*/
function onCloseRequest(result)
{
eventSource.close()

Object.defineProperty(self, 'subscriptionId', {value: null})

self.emit('close')
if(server)
server.close(self.emit.bind(self, 'close'))
else
{
eventSource.close()
self.emit('close')
}

return result
}
Expand All @@ -215,11 +219,11 @@ function SubscribeContext(options)
*/
this.update = function(data)
{
data.subscriptionId = this.subscriptionId

return this
.then(function()
{
data.subscriptionId = this.subscriptionId

requestOptions.uri.path = '/NGSI10/updateContextSubscription'
requestOptions.body = data

Expand All @@ -233,10 +237,10 @@ function SubscribeContext(options)
*/
this.close = function()
{
var data = {subscriptionId: this.subscriptionId}

return this.then(function()
{
var data = {subscriptionId: this.subscriptionId}

requestOptions.uri.path = '/NGSI10/unsubscribeContext'
requestOptions.body = data

Expand Down

0 comments on commit 1b10c9e

Please sign in to comment.