다음 코드를 실행하면 순차적으로 MongoDB에 연결 한 다음 javascript에서 async.waterfall을 사용하여 프로그램이 예상대로 종료되지 않습니다. 대신 그냥 'DB 폐쇄 "줄 끝에서 기다리는 나타납니다.왜 내 async.waterfall 자바 스크립트 순차 코드가 끝나지 않습니까?
$ node test-async2.js
hit connectMongo
Connected correctly to server, DB: notes
hit closeMongo
DB closed
[program just waits here, doesn't end]
내가 종료 프로그램을 예상하고 있었다. 내가?
const
async = require('async'),
MongoClient = require('mongodb').MongoClient,
url = 'mongodb://localhost:27017/notes';
function connectMongo(next) {
console.log('hit connectMongo');
MongoClient.connect(url, function(err, db) {
console.log("Connected to server, DB: " + db.databaseName);
next(null, db);
});
}
function closeMongo(db, next) {
console.log('hit closeMongo');
db.close;
next(null, "DB closed");
}
// perform connect then close sequentially
async.waterfall([
connectMongo,
closeMongo,
], function (err, result) {
if (err) throw err;
console.log(result);
});
, 즉 무엇인가 'Ctrl + C'가 도움이 될 것 같아. 너는 너의 프로그램을 멈춘다. 나는 그것이 자동적으로 끝날 것이라고 생각하지 않는다. – Shrabanee
'close'라고 부르시겠습니까? 괄호는 없습니다. – cartant
@cartant - 그게 전부 고마워. 나는 너무 오랫동안 나는 어리석은 실수를 보지 못했다. 다시 한 번 감사드립니다! – Jon