-
Notifications
You must be signed in to change notification settings - Fork 3
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
Priority of async tasks #2
Comments
Have you tried multi-threading? e.g /* thread 2 */
void imgLoader(...) {
data = net.get(...);
}
/* callback */
void onInitialized() {
thread.run(imgLoader, args...);
}
/* callback */
void onChangeScene() {
if (scene.type == SC_BOOK) { // switch
await(imgResult);
...
}
}
/* main thread */
int main() {
prepare();
app.run(win);
} |
Thanks for replying. From the very first day developing this application, I've used asynchronous task to load images. Interestingly, I've found that asynchronous functions blocked the UI just a little bit, especially when the internet is slow, as pointed out at this. And yes, I've successfully implemented network requests in another thread and everything worked alright. But that was a different problem. This issue is more like, how to pause an async task, and resume it later. The very common use case of this is when you have many async tasks, but some tasks have higher priority, e.g. your homepage has 30 images, but you want to load images that are in the perceptible field first, as soon as the user scroll to that point. |
I think, all images in the page should be loaded after the user accesses the page. void imgLoader(...) {
data[imgIndex] = net.get();
setStateOrYield(loadingState, ...);
}
void onScroll(...) {
img = getImage(idx);
if (img) {
img.show(position);
}
else {
delayOrWaitOrShowAlternativeImg(...);
}
} |
I did some research on pausing and resuming async tasks in Vala, still no luck though. I think your approach was clear and feasible to implement. By delaying loading and instead of loading and pausing, this would be more efficient. Thanks! |
Priority of async tasks is required to make the GUI fast.
For example, when
Home
is loading, clicking on aBook
to view to see the book's cover and preview pages must have higher priority than async tasks that are loading images inHome
.The text was updated successfully, but these errors were encountered: