首页 > 其他分享 >任务执行的洋葱模型

任务执行的洋葱模型

时间:2023-10-07 17:47:29浏览次数:43  
标签:taskUtils console log 模型 任务 next 洋葱 currentIndex ._

class TaskUtils {
    constructor() {
        this.currentIndex = 0
        this.tasks = []
        this._isRunning = false
        this._next = async () => {
            this.currentIndex++;
            await this._runTask();
        }
    }
    addTask(task) {
        this.tasks.push(task)
    }
    run() {
        if (this._isRunning || !this.tasks.length) {
            return
        }
        this._isRunning = true
        this._runTask()
    }
    async _runTask() {
        if (this.currentIndex >= this.tasks.length) {
            this._reset()
            return;
        }
        const i = this.currentIndex
        const task = this.tasks[this.currentIndex]
        await task(this._next)
        const j = this.currentIndex
        console.log(i, j, this.currentIndex)
        if (i === j) {
           await this._next()
        }
    }
    _reset() {
        this.currentIndex = 0
        this.tasks = []
        this._isRunning = false
    }
}

const taskUtils = new TaskUtils();

taskUtils.addTask(async (next) => {
    console.log('1 start')
    await next()
    console.log('1 end')
})

taskUtils.addTask( async () => {
    console.log('2')
})
taskUtils.addTask( async (next) => {
    console.log('3')
    await next();
    console.log('4')
})
taskUtils.addTask( async () => {
    console.log('5')
})
taskUtils.addTask( async (next) => {
    console.log('6')
    await next();
    console.log('7')
})
taskUtils.run()

 

标签:taskUtils,console,log,模型,任务,next,洋葱,currentIndex,._
From: https://www.cnblogs.com/stof/p/17747026.html

相关文章

  • 【AI 模型】首个 Joy 模型诞生!!!全民生成 Joy 大片
    接上一篇文章“只要10秒,AI生成IP海报,解放双手”,这次是全网第一个“共享joy模型”,真的赚到了!经过这段时间无数次的探索、试错、实验,最终积累了非常多的训练经验,在不同IP角色的训练上实际上需要调试非常多的参数以及素材。本次成功完成了Joy的Lora模型,虽然在泛化以及场景上未来还......
  • Django实战项目-学习任务系统-用户登录
    第一步:先创建一个Django应用程序框架代码1,先创建一个Django项目django-adminstartprojectmysite将创建一个目录,其布局如下:mysite/manage.pymysite/__init__.pysettings.pyurls.pyasgi.pywsgi.py2,再创建一个Dja......
  • 重新编译kyuubi-1.6.1版本使其提交flink sql流式任务时不阻塞
    kyuubi-1.6.1版本对于flinksql的支持不是很好,在提交流式任务时会阻塞进程,为了修复这个缺陷,需要修改源代码并重新编译待编译的kyuubi版本:kyuubi-1.6.1-incubating适配的flink版本:flink-1.14.41、下载kyuubi-1.6.1-incubating版本的源代码,并导入IDEA中gitclone-bv1.6.1-incu......
  • 对常用I/O模型进行比较说明
     #一、网络I/O模型阻塞型、非阻塞型、复用型、信号驱动型、异步#1、阻塞型I/O模型(blockingIO 阻塞IO模型是最简单的I/O模型,用户线程在内核进行IO操作时被阻塞用户线程通过系统调用read发起I/O读操作,由用户空间转到内核空间。内核等到数据包到达后,然后将接收......
  • 一个多线程任务流程控制
    importthreadingclassQue_test:def__init__(self):#创建条件变量和计数器self.cv=threading.Condition()self.counter=1deffirst(self):withself.cv:print('first')self.counter+=1......
  • 生成一个指数回归模型,以预测温度与其他变量的关系, 并给出模型的函数
    #导入所需的库importpandasaspdimportnumpyasnpimportmatplotlib.pyplotaspltimportseabornassnsfromsklearn.linear_modelimportLinearRegressionfromsklearn.metricsimportmean_squared_error,r2_score#指定支持中文的字体,例如SimHei或者Microsoft......
  • 大语言模型黑盒被打破;Meta 元宇宙硬件亏损可能高于市场共识丨 RTE 开发者日报 Vol.60
     开发者朋友们大家好:这里是「RTE开发者日报」,每天和大家一起看新闻、聊八卦。我们的社区编辑团队会整理分享RTE (RealTimeEngagement) 领域内「有话题的新闻」、「有态度的观点」、「有意思的数据」、「有思考的文章」、「有看点的会议」,但内容仅代表编辑的个人观点,欢迎......
  • GPU通用计算编程模型
    这是我阅读General-PurposeGraphicsProcessorArchitecture的一篇笔记,本文对应书中第二章的内容。执行模型现代GPU普遍采用SIMD来实现数据级(data-level)并行,程序员通过诸如CUDA等API以在GPU上启动一系列的线程(thread)执行工作。其中,每个线程可以有独立的执行路径(executionpath),......
  • 三维模型3DTile格式轻量化的数据压缩与性能平衡关系分析
    三维模型3DTile格式轻量化的数据压缩与性能平衡关系分析 对于三维模型的3DTile格式轻量化处理,数据压缩和性能之间的平衡关系是一个重要的考虑因素。以下是这两者关系的详细分析:1、数据压缩与加载速度:显然,更高级别的压缩可以创造更小的文件大小,从而加快从服务器到客户端的传输......
  • 基于AI模型的验证码安全识别(B站,知乎等)
     bilibili汉字识别顺序验证码实现基本思路:  先利用Selenium模拟登录,当然在这之前做好请求伪装,get方法使边框最大化,并且将系统的windows窗口缩放比例设置为100%,不推荐125%,否则可能导致xpath定位不准,使用send_key()方法导入账号密码,隐式等待验证码出现,这里B站可以获取验证......