We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
No description provided.
The text was updated successfully, but these errors were encountered:
题目如下:
new Queue().task(1000, function () { console.log(1); }).task(2000, function () { console.log(2); }).start()
Sorry, something went wrong.
方案1:
function Queue1() { this.queue = [] this.task = (time, fn) => { this.queue.push({fn, time}) return this } this.start = () => { let deffer = 0 for (let i of this.queue) { deffer += i.time setTimeout(i.fn, deffer) } } }
方案2:
function Queue2() { this.queue = [] this.task = (time, fn) => { this.queue.push(function (resolve) { setTimeout(function () { resolve(fn()) }, time) }) return this } this.start = async () => { for (let i of this.queue) { await new Promise(i) } } }
No branches or pull requests
No description provided.
The text was updated successfully, but these errors were encountered: