@dtu-olp-2024/kafka-nocobase
Version:
A NocoBase plugin for Apache Kafka integration, supporting message publishing, topic management, and event-driven workflows. Built for the DTU GreenHope project.
19 lines (17 loc) • 565 B
JavaScript
/**
* @template T
* @param { (...args: any) => Promise<T> } [asyncFunction]
* Promise returning function that will only ever be invoked sequentially.
* @returns { (...args: any) => Promise<T> }
* Function that may invoke asyncFunction if there is not a currently executing invocation.
* Returns promise from the currently executing invocation.
*/
module.exports = asyncFunction => {
let promise = null
return (...args) => {
if (promise == null) {
promise = asyncFunction(...args).finally(() => (promise = null))
}
return promise
}
}