user478250
user478250

Reputation: 259

NowJS server event notifications

I'm trying to implement a system where an external server (SuperFeedr) sends a request to my server (running Node) and my server processes, then sends that data straight to the client in realtime using NowJS.

Problem is, I cannot access the everyonce namespace in my server functions since it has to be initialized after the listen() function is called which has to happen after the functions are declared. So basically:

Needs:

NowJS->Listen->Server functions->everyone variable->NowJS

Seems I have a dependency loop and I have no idea how to resolve it.

Upvotes: 0

Views: 292

Answers (1)

thejh
thejh

Reputation: 45578

Start all of them independently. When one of them is up, put a reference to it into a shared parent scope. When e.g. the server receives a notification, just drop it if nowjs isn't ready yet. Simplified example:

var a, b;
initializeA(function(a_) {
  a = a_
  a.on('request', function(request, response) {
    if (!b) {
      // B isn't ready yet, drop the request
      return response.end()
    }
    // ...
  })
})
initializeB(function(b_) {
  b = b_
  b.on('request', function(request, response) {
    if (!a) {
      // A isn't ready yet, drop the request
      return response.end()
    }
    // ...
  })
})

Upvotes: 1

Related Questions