节点写入流挂起
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了节点写入流挂起相关的知识,希望对你有一定的参考价值。
此节点脚本在records written: 442
的最后一行之后挂起。
这意味着finish
事件已经被解雇,但我不知道如何结束整个脚本。
const N3 = require('n3');
const fs = require('fs');
const neo4j = require('neo4j-driver').v1;
const uri = 'bolt://localhost';
const user = 'neo4j';
const password = 'sms1993662';
const driver = neo4j.driver(uri, neo4j.auth.basic(user, password));
const session = driver.session();
let streamParser = N3.StreamParser();
let rdfStream = fs.createReadStream('/Users/simonshapiro/Documents/javascript/rdf_graphlib_js/data/sh.tll')
let number_of_rows = 0;
function DatastoreWriter () {
let writer = new require('stream').Writable({objectMode: true});
writer._write = (triple, encoding, done) => {
console.log(triple);
const mergePromise = session.run(
`MERGE (n:Unidentified {id:"${triple.subject}"})`
);
mergePromise.then(() => {
number_of_rows += 1;
done();
})
.catch((e)=>{
console.log('error', e);
done();
});
}
return writer
};
const neo4jWriter = new DatastoreWriter();
rdfStream.pipe(streamParser);
streamParser.pipe(neo4jWriter);
neo4jWriter.on('finish', ()=>{
session.close();
console.log('records written: ', number_of_rows);
});
答案
根据documentation,驱动程序应该关闭,可以这样做:
neo4jWriter.on('finish', ()=>{
session.close(() => driver.close());
console.log('records written: ', number_of_rows);
});
以上是关于节点写入流挂起的主要内容,如果未能解决你的问题,请参考以下文章