mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Fixup Join node to apply reduce_fixup asynchronously
This commit is contained in:
parent
4609ee75b6
commit
9efd48fe51
@ -266,7 +266,15 @@ module.exports = function(RED) {
|
|||||||
function apply_f(exp, accum, count) {
|
function apply_f(exp, accum, count) {
|
||||||
exp.assign("N", count);
|
exp.assign("N", count);
|
||||||
exp.assign("A", accum);
|
exp.assign("A", accum);
|
||||||
return RED.util.evaluateJSONataExpression(exp, {});
|
return new Promise((resolve,reject) => {
|
||||||
|
return RED.util.evaluateJSONataExpression(exp, {}, (err, result) => {
|
||||||
|
if (err) {
|
||||||
|
reject(err);
|
||||||
|
} else {
|
||||||
|
resolve(result);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function exp_or_undefined(exp) {
|
function exp_or_undefined(exp) {
|
||||||
@ -296,9 +304,12 @@ module.exports = function(RED) {
|
|||||||
return msgs.reduce((promise, msg) => promise.then(accum => apply_r(reduce_exp, accum, msg, msg.parts.index, count)), Promise.resolve(accum))
|
return msgs.reduce((promise, msg) => promise.then(accum => apply_r(reduce_exp, accum, msg, msg.parts.index, count)), Promise.resolve(accum))
|
||||||
.then(accum => {
|
.then(accum => {
|
||||||
if(reduce_fixup !== undefined) {
|
if(reduce_fixup !== undefined) {
|
||||||
accum = apply_f(reduce_fixup, accum, count);
|
return apply_f(reduce_fixup, accum, count).then(accum => {
|
||||||
|
node.send({payload: accum});
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
node.send({payload: accum});
|
||||||
}
|
}
|
||||||
node.send({payload: accum});
|
|
||||||
});
|
});
|
||||||
}).catch(err => {
|
}).catch(err => {
|
||||||
throw new Error(RED._("join.errors.invalid-expr",{error:e.message}));
|
throw new Error(RED._("join.errors.invalid-expr",{error:e.message}));
|
||||||
|
@ -1319,24 +1319,28 @@ describe('JOIN node', function() {
|
|||||||
initContext(function () {
|
initContext(function () {
|
||||||
var n1 = helper.getNode("n1");
|
var n1 = helper.getNode("n1");
|
||||||
var n2 = helper.getNode("n2");
|
var n2 = helper.getNode("n2");
|
||||||
n2.on("input", function(msg) {
|
|
||||||
try {
|
try {
|
||||||
msg.should.have.property("payload");
|
n2.on("input", function(msg) {
|
||||||
msg.payload.should.equal(((((1+1*2)+2*2)+3*2)+4*2)*3);
|
try {
|
||||||
done();
|
msg.should.have.property("payload");
|
||||||
}
|
msg.payload.should.equal(((((1+1*2)+2*2)+3*2)+4*2)*3);
|
||||||
catch(e) { done(e); }
|
done();
|
||||||
});
|
}
|
||||||
n1.context().flow.set(["one","two","three"],[1,2,3],"memory",function(err){
|
catch(e) { done(e); }
|
||||||
if(err){
|
});
|
||||||
done(err);
|
n1.context().flow.set(["one","two","three"],[1,2,3],"memory",function(err){
|
||||||
} else{
|
if(err){
|
||||||
n1.receive({payload:3, parts:{index:2, count:4, id:222}});
|
done(err);
|
||||||
n1.receive({payload:2, parts:{index:1, count:4, id:222}});
|
} else{
|
||||||
n1.receive({payload:4, parts:{index:3, count:4, id:222}});
|
n1.receive({payload:3, parts:{index:2, count:4, id:222}});
|
||||||
n1.receive({payload:1, parts:{index:0, count:4, id:222}});
|
n1.receive({payload:2, parts:{index:1, count:4, id:222}});
|
||||||
}
|
n1.receive({payload:4, parts:{index:3, count:4, id:222}});
|
||||||
});
|
n1.receive({payload:1, parts:{index:0, count:4, id:222}});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}catch(err) {
|
||||||
|
done(err);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user