鸿蒙仓颉语言【线程thread】
线程
创建一个独立的线程worker,去执行一项任务,在仓颉里面非常简单,spawn{工作任务代码}
这样就可以了,示例如下:
spawn{
currentThreadRuns(e)
}
鸿蒙更多内容,结尾扫
复杂一点的例子
public init(maxWaitingJob: Int64, fullJobQueueStrategy!: WorkerStrategy = Block,
abilities!: Array<(Event, (Event)->Event)> = []){
queue = JobQueue(maxWaitingJob, strategy: fullJobQueueStrategy, abilities: this.abilities)
register(abilities)
spawn{
while(!retired.load()){
var e = queue.dequeue()
while(!e.end){
e = this.abilities[e](e)
}
}
}
}
原文地址:https://blog.csdn.net/m0_70748845/article/details/140560253
免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!