我有一个代码,我得到一个双工流,在该函数中,我调用一个回调函数,它返回redis的值。
function (index, arr, null, callback) {
const streamObject = stream;
const Id = arr[index].split(':')[0];
const Version = arr[index].split(':')[1];
console.log("STREAM RECEIVED IN SECOND 1");
console.log(streamObject);//printing for the first time
var response = this.ts.service(Id, Version, streamObject, (fn, type) => {
console.log("STREAM RECEIVED IN SECOND 2");
console.log(streamObject);
}
这里当我第一次打印流对象时,我得到了流对象,如下所示
STREAM RECEIVED IN SECOND 1
Stream {
domain:
Domain {
domain: null,
_events: { error: [Function] },
_eventsCount: 1,
_maxListeners: undefined,
members: [] },
_events:
{ end: [Function],
data: [Function],
drain: [Function: ondrain],
error: [Function: onerror],
close: [Function: cleanup] },
_eventsCount: 5,
_maxListeners: undefined,
writable: true,
readable: true,
paused: false,
autoDestroy: true,
write: [Function],
push: [Function],
queue: [Function],
end: [Function],
destroy: [Function],
pause: [Function],
resume: [Function] }
并且第二次得到
第二次收到的流量
Stream {
domain:
Domain {
domain: null,
_events: { error: [Function] },
_eventsCount: 1,
_maxListeners: undefined,
members: [] },
_events: { end: [Function], data: [Function] },
_eventsCount: 2,
_maxListeners: undefined,
writable: false,
readable: false,
paused: false,
autoDestroy: true,
write: [Function],
push: [Function],
queue: [Function],
end: [Function],
destroy: [Function],
pause: [Function],
resume: [Function],
root: null }
因此流被修改我不知道为什么会发生这种情况,我没有对所调用函数中的流做任何事情。
这就是我的服务方法看起来我正在调用的方式
service(id, vn, requestObject, callback) {
log.info("entering transformer service");
var transformerCombinedKey = id + vn;
if (!_.isString(transformerId)) {
throw new TypeError("Expected a string for transformerId");
}
if (!(transformerCombinedKey in this.functionRepositoryStore)) {
//FIXME: after using cache as a implementation should ret
var persistenceClientPromise = this.persistenceClient.getTransformerByIdAndVersion(transformerId, versionNumber)
persistenceClientPromise.then(
(aJSONStringifiedTransformer) => {
if (!aJSONStringifiedTransformer) {
callback(new Error("The given transformerId, " + transformerId + ", was not found."));
return;
}
this.functionRepositoryStore[transformerCombinedKey] = JSON.parse(aJSONStringifiedTransformer).transformerFunction;
this.transformerTypeRepository[transformerCombinedKey] = JSON.parse(aJSONStringifiedTransformer).transformerType;
const code = "var _ = require('lodash'); console.log('runnig VM1'); module.exports = " + this.functionRepositoryStore[transformerCombinedKey] + ';';
var transformerFunction = vm.runInNewContext(code, sandbox);
console.log("Calling callback inside the transformer service===1 ");
console.log(JSON.stringify(transformerFunction));
callback(transformerFunction, this.transformerTypeRepository[transformerCombinedKey]);
return
},
(error) => {
log.error("Error while getting transformer for Id " + transformerId + " and versionNumber " + versionNumber);
callback(error, null);
});
} else {
const code = "var _ = require('lodash'); console.log('runnig VM2'); module.exports = " + this.functionRepositoryStore[transformerCombinedKey] + '; ';
var transformerFunction = vm.runInNewContext(code, sandbox);
console.log("Calling callback inside the transformer service=== ");
console.log(JSON.stringify(transformerFunction));
callback(transformerFunction, this.transformerTypeRepository[transformerCombinedKey]);
}
}
}
这个问题我看到第一次点击我的应用程序,当我再次点击它而不重新启动应用程序时,它工作正常流仍然是双工。 如果我删除我对redis这个方法的调用,那么流不会改变它的工作正常。
我正在使用瀑布,这是我的瀑布模型的第二个功能,如
async.waterfall([func1,func2], function (err, result) {
if (err) {
console.log(err);
reject(err);
} else {
fulfill(result);
}
});
这第一个函数也做同样的事情,但它工作正常,第一个的输出传递给第二个。 这就是我创建流的方式
let streamParser = JSONStream.parse('*');
streamParser.on('data', fn);
let toPassStreamObject = streamObject.pipe(JSONStream.stringify())
.pipe(streamParser)
streamObject是我从我的数据库中获取的流。
fn (data) {
data['Date'] = data["month"];
delete data['month'];
}
我坚持了一段时间。如何防止流变化。
这是我之前的post
的引用