Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NodeJS 無法結束 #36

Open
Chen-Michael opened this issue Aug 14, 2020 · 1 comment
Open

NodeJS 無法結束 #36

Chen-Michael opened this issue Aug 14, 2020 · 1 comment

Comments

@Chen-Michael
Copy link

Chen-Michael commented Aug 14, 2020

db.collection('rooms').get().then(rooms => {
	var roomID = [];

	rooms.forEach(room => {
		roomID.push(room.id);
	});

	return roomID;
}).then(async roomID => {
	for (let id of roomID) {
		let users = await db.collection('/room_users/' + id + '/list').get();
		for (let user of users.docs) {
			try {
				let userData = await admin.auth().getUser(user.id);
			} catch (error) {
				console.log(error);
			}
		}
	}
}).then(() => {
	console.log('done.');
});

第二個版本

async function foo() {
	let rooms = await db.collection('rooms').get();
	for (let room of rooms.docs) {
		let users = await db.collection('/room_users/' + room.id + '/list').get();
		for (let user of users.docs) {
			try {
				let userData = await admin.auth().getUser(user.id);
				console.log(userData.uid);
			} catch (error) {
				console.log(error);
			}
		}
	}
	console.log('Done.');
}

console.log('Start.');
foo();

遇到的問題

let userData = await admin.auth().getUser(user.id);

有這一行 NodeJS 無法結束, 已確定沒有其他 error , 也有輸出 done.

但就是結束不了

嘗試過的解法

將 let userData = await admin.auth().getUser(user.id); 移除

輸出 done. 後能順利結束

@a0000778
Copy link

你需要補上 admin 這個變數及其下方法的程式碼

方法名稱看起來有建立資料庫連線之類的行為,很可能是用完沒關閉,或者建立時沒 .unref()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants