我使用const代替var。
const allUsers = Users.find().fetch();
if (allUsers.length === 0) {
createDummyUsers();
// I want to say allUsers = createDummyUsers(); instead but allUsers is const and it's async
}
问题是我无法重新分配所有用户(如果长度=== 0),因为它是一个常量。调用异步函数并在此等待响应的约定是什么?这是我试图等待的功能:
const createDummyUsers = function () {
console.log('// seeding users…');
createUser('Bruce', 'dummyuser1@telescopeapp.org');
createUser('Arnold', 'dummyuser2@telescopeapp.org');
createUser('Julia', 'dummyuser3@telescopeapp.org');
};