Skip to content

Commit b0de949

Browse files
committed
routes/application: Preload Rust Playground crates list after the app has been open for 1 sec
1 parent fb4b26f commit b0de949

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

app/routes/application.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@ import { action } from '@ember/object';
22
import Route from '@ember/routing/route';
33
import { inject as service } from '@ember/service';
44

5+
import { didCancel, rawTimeout, task } from 'ember-concurrency';
6+
57
export default class ApplicationRoute extends Route {
68
@service progress;
79
@service session;
10+
@service playground;
811

912
beforeModel() {
1013
// trigger the task, but don't wait for the result here
@@ -15,10 +18,22 @@ export default class ApplicationRoute extends Route {
1518
//
1619
// eslint-disable-next-line ember-concurrency/no-perform-without-catch
1720
this.session.loadUserTask.perform();
21+
22+
// trigger the preload task, but don't wait for the task to finish.
23+
this.preloadPlaygroundCratesTask.perform().catch(error => {
24+
// ignore task cancellation errors
25+
if (!didCancel(error)) throw error;
26+
});
1827
}
1928

2029
@action loading(transition) {
2130
this.progress.handle(transition);
2231
return true;
2332
}
33+
34+
@task(function* () {
35+
yield rawTimeout(1000);
36+
this.playground.loadCrates();
37+
})
38+
preloadPlaygroundCratesTask;
2439
}

0 commit comments

Comments
 (0)