-
Notifications
You must be signed in to change notification settings - Fork 0
/
request.js
33 lines (32 loc) · 1.11 KB
/
request.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/*jslint node: true */
/* global -Promise */
"use strict";
module.exports = function (Domain) {
Domain.prototype.request = function (to, body, options) {
var _this = this;
return this.uid()
.then(function (mailbox) {
var from = ['request', mailbox];
var resp = _this.waitFor(from, options)
.then(function (ctxt) {
return [ctxt.body, ctxt.options, ctxt];
})
.catch(function (err) {
var ctxt = new _this.Message({
body: err
, options: { statusCode: 504 }
, domain: _this
});
return ['Request did not return in time: ' + to.join('/'), ctxt.options, ctxt];
});
if (!_this.send(to, from, body, options)) {
_this.send(from, [], 'Service unavailable ' + to.join('/'), { statusCode: 503 })
}
return resp;
});
};
Domain.prototype.Message.prototype.request = function () {
var d = this.domain;
return d.request.apply(d, arguments);
};
};