これを行う良い方法を見つけることはできませんが、これが私の基本的な方法です。その目標は、正規表現に一致するメッセージが見つかるまでオブジェクトの状態を観察することです。
Cylon.waitForMessage(regex) {
check(regex, RegExp);
const observer = this.connections.find({
name: 'messages'
}).observe({
changed: function (doc) {
console.log(doc.lastMessage) // this is the last message to scan.
}
});
let promise = new Promise((resolve, reject) => {
// need to find the last message here and check if it matches regex
}).then(() => observer.stop());
return Promise.await(promise);
}
これを行う適切な方法は何ですか?promise が完了した後、リスナーまたはオブザーバーをどのように停止できますか?