Created
September 5, 2023 08:57
-
-
Save un4ckn0wl3z/aeef186fdf16a51b21c0d87fb30b5759 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Service { | |
static async task(numv: number){ | |
return new Promise((resolve, reject) => { | |
setTimeout(() => { | |
console.log('Task completed ' + numv) | |
resolve(numv) | |
}, 3000) | |
}) | |
}} | |
class Controller { | |
async controllerHandler(taskId: number){ | |
try { | |
console.log('Consuming...task ' + taskId) | |
await Service.task(taskId) | |
console.log('--------------------------------------------') | |
} catch (e) { | |
console.log(e) | |
} | |
} | |
} | |
// ------------------------------------------------------------------------------ | |
const controller = new Controller() | |
async function* foo() { | |
yield 1; | |
yield 2; | |
yield 3; | |
yield 4; | |
yield 5; | |
yield 6; | |
yield 7; | |
yield 8; | |
yield 9; | |
yield 10; | |
yield 11; | |
yield 12; | |
yield 13; | |
yield 14; | |
yield 15; | |
} | |
(async function () { | |
for await (const num of foo()) { | |
await controller.controllerHandler(num) | |
} | |
})(); | |
// console.log('Consuming...task ' + taskId) | |
// Service.task(taskId).then(() => { | |
// }) | |
// class Manager { | |
// static async controllerHandler(taskId: number){ | |
// try { | |
// console.log('Consuming...task ' + taskId) | |
// await Service.task(taskId) | |
// console.log('--------------------------------------------') | |
// } catch (e) { | |
// console.log(e) | |
// } | |
// } | |
// } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment