我正在尝试将新的promise
库与meteor一起使用,但它没有记录。 Promise.async
和Promise.await
(它们在库中声明的主要功能)的适当用法是什么?这就是我的尝试
MyModule._writeCommand = function (command) {
let observers = []
return new Promise((resolve, reject) => {
this._commands.write(`${command}\r`, 'utf8');
observers.push(this.connections.find({
name: 'commands'
lastMessage: { $regex: /^\:$/ }
}).observe({ changed: resolve }));
}).finally(() => {
return Promise.each(observers, (o) => o.stop());
});
}
MyModule.myFunction = Promise.async(function (command, message) {
const promise = this._writeCommand('Execute startup')
.then(() => new Promise((resolve, reject) => {
this.connections.find({
name: 'messages',
'lastMessage.message': { $regex: message }
}).observe({ changed: resolve });
}));
return Promise.await(promise);
});
这是使用promise
包的适当方法吗?