Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let resolveOnConsumption: (e: Error) => void
- const consumptionPromise = new Promise<Error>(resolve => {
- resolveOnConsumption = resolve
- })
- await consumer.run({
- eachMessage: async ({ message }) => {
- resolveOnConsumption()
- },
- })
- const timeoutPromise = new Promise<'timeout'>(res => setTimeout(() => res('timeout'), timeoutMs))
- return Promise.race([errorPromise, timeoutPromise])
- .then(timeoutOrConsumed => {
- if (timeoutOrConsumed === 'timeout') {
- throw new Error('Message not consumed before the timeout')
- }
- })
- .finally(() => consumer.disconnect())
Advertisement
Add Comment
Please, Sign In to add comment