-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
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
Topic5: Coroutine & Asynchronous programming #74
Comments
As showed before, does the load file or wait for some task finished required by the program to run, if it is, I think there is no way to optimize it, but I suggest that, we could load all file and some necessary task when the program initialize, and do some normal operations of storing data to container or parsing. use big memory and a lot of time during start up initialize to get a faster and easy program running later. if not, we could use observer Pattern to solve this program, load file module hold an instance of the main module, after load file finished or task is finished, use that instance to notice main module do other thing. 上面说的加载文件和等待某个任务完成,是不是程序运行下去的必要条件, 如果是,我觉得没法优化, 但是建议程序在开始运行的时候,初始化加载全部需要的文件, 并且做一些固定的存储容器和解析的操作。用大的内存来和长的初始化时间换取程序后面运行的方便和快速。 如果不是,是不是可以用 observer 模式来解决这个问题, 加载文件的模块保留一个 主模块的对象, 在完成加载或者任务完成之后,再通知主模块进行其他的任务。 |
@MacroGu Yes, basically, people loaded all the resources that the application required when launching the application. Observer Pattern you mentioned is a good way to solve the problem that the task blocking the main thread. The disadvantage of this way is it needs a callback function to receive the notice when the task finished, which is unfriendly in terms of synchronizing code. Actually, some coder hopes all the business code run in one thread and with a high performance, besides, the function can transfer its context and can restore its context when the program needs. The answer is Coroutine. The project https://github.com/ketoo/NFCoroutine now I am writing is a demo about Coroutine. Another project https://github.com/cloudwu/coroutine written by Cloud.Wu is the same kind of project. |
Background:
Normally, the program executes a sequence of computations by line. Sometimes, the codes will spend a lot of time in reading files or waiting for something, as a result, the program blocking. Is there have any way to optimize this situation?
Please leave messages here for discussing.
在通常情况下,我们的程序只会顺序的执行一系列的计算任务.在一些情况下,程序会花费大量的时间在加载文件或等待某个任务完成,从而导致程序运行阻塞.那么是否有什么办法可以优化这个问题呢?
请留下你的看法, 让我们一起讨论吧!
The text was updated successfully, but these errors were encountered: