docs(toh): improve `getHeroesSlowly` in ToH-4/5 (#2443) (#2991)

This commit is contained in:
Ward Bell 2016-12-15 11:13:22 -08:00 committed by GitHub
parent 562c629d22
commit b7a9a4524f
2 changed files with 9 additions and 6 deletions

View File

@ -14,12 +14,14 @@ export class HeroService {
}
// #enddocregion get-heroes, just-get-heroes
// #enddocregion
// See the "Take it slow" appendix
// #docregion get-heroes-slowly
getHeroesSlowly(): Promise<Hero[]> {
return new Promise<Hero[]>(resolve =>
setTimeout(resolve, 2000)) // delay 2 seconds
.then(() => this.getHeroes());
return new Promise(resolve => {
// Simulate server latency with 2 second delay
setTimeout(() => resolve(this.getHeroes()), 2000);
});
}
// #enddocregion get-heroes-slowly
// #docregion

View File

@ -11,9 +11,10 @@ export class HeroService {
}
getHeroesSlowly(): Promise<Hero[]> {
return new Promise<Hero[]>(resolve =>
setTimeout(resolve, 2000)) // delay 2 seconds
.then(() => this.getHeroes());
return new Promise(resolve => {
// Simulate server latency with 2 second delay
setTimeout(() => resolve(this.getHeroes()), 2000);
});
}
// #docregion getHero