I create a report service in which one process sends a request, retrieves a token, and then passes the token to another process, from which we request a report service and return the results.
Given this code, how to implement a blocking call until it is suspended?
var util = require('util')
, events = require('events')
, pg = require('pg')
function QueryHandler(sql) {
this.paused = true
pg.connect(connectionString, function(err, client) {
var query = client.query(sql)
query.on('row', function(row) {
if (this.paused) {
}
this.emit(row)
}.bind(this))
}.bind(this))
}
util.inherits(QueryHandler, events.EventEmitter)
QueryHandler.prototype.resume = function() {
this.paused = false
}
Here is an interaction diagram explaining what I'm trying to achieve:
http://teksol.info.s3.amazonaws.com/reporting-service.png
- Web browser requests frontend web server for report
- Frontend web server requests a reporting service for a token related to a specific request
- At the same time, the reporting service connects to PostgreSQL and sends a query
- The frontend web server returns the report service URL and token back to the web browser.
- - Ajax ( )
- -.
, 3 -, . , , , . , , , - ? , !