Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 20s
Build & Deploy / 🧪 QA (push) Failing after 34s
Build & Deploy / 🏗️ Build (push) Has started running
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🧪 Smoke Test (push) Has been cancelled
Build & Deploy / ⚡ Lighthouse (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
20 lines
557 B
Plaintext
20 lines
557 B
Plaintext
'use strict'
|
|
|
|
/**
|
|
* Listens for an event on an object and resolves a promise when the event is emitted.
|
|
* @param {Object} emitter - The object to listen to.
|
|
* @param {string} event - The name of the event to listen for.
|
|
* @param {Function} fn - The function to call when the event is emitted.
|
|
* @returns {Promise} A promise that resolves when the event is emitted.
|
|
*/
|
|
function once (emitter, event, fn) {
|
|
return new Promise(resolve => {
|
|
emitter.on(event, (...args) => {
|
|
fn(...args)
|
|
resolve()
|
|
})
|
|
})
|
|
}
|
|
|
|
module.exports = { once }
|