example(toh-4,5): getHeroesSlowly() to return getHeroes() (#2152)

* example(dart/toh-4,5): getHeroesSlowly() to return getHeroes()

Have `getHeroesSlowly()` delay and then return the value of
`getHeroes()`. This makes it easier for user’s performing the tutorial
to keep this slower method as they evolve toh-5 into toh-6.

* example(ts/toh-4,5): getHeroesSlowly() to return getHeroes()

Have `getHeroesSlowly()` delay and then return the value of
`getHeroes()`. This makes it easier for user’s performing the tutorial
to keep this slower method as they evolve toh-5 into toh-6.
This commit is contained in:
Patrice Chalin 2016-08-26 14:39:57 -07:00 committed by Ward Bell
parent fd8fb70f07
commit 2bd9946bda
6 changed files with 8 additions and 11 deletions

View File

@ -17,7 +17,7 @@ class HeroService {
// See the "Take it slow" appendix // See the "Take it slow" appendix
// #docregion get-heroes-slowly // #docregion get-heroes-slowly
Future<List<Hero>> getHeroesSlowly() { Future<List<Hero>> getHeroesSlowly() {
return new Future.delayed(const Duration(seconds: 2), () => mockHeroes); return new Future.delayed(const Duration(seconds: 2), getHeroes);
} }
// #enddocregion get-heroes-slowly // #enddocregion get-heroes-slowly
// #docregion // #docregion

View File

@ -13,7 +13,7 @@ class HeroService {
// #enddocregion getHeroes-stub, empty-class, final // #enddocregion getHeroes-stub, empty-class, final
/* /*
// #docregion getHeroes-stub // #docregion getHeroes-stub
List<Hero> getHeroes() {} List<Hero> getHeroes() {} // stub
// #enddocregion getHeroes-stub // #enddocregion getHeroes-stub
*/ */
// #docregion final // #docregion final

View File

@ -13,8 +13,7 @@ export class HeroService {
// #enddocregion empty-class, getHeroes-stub, full // #enddocregion empty-class, getHeroes-stub, full
/* /*
// #docregion getHeroes-stub // #docregion getHeroes-stub
getHeroes(): void { getHeroes(): void {} // stub
}
// #enddocregion getHeroes-stub // #enddocregion getHeroes-stub
*/ */
// #docregion full // #docregion full

View File

@ -18,8 +18,8 @@ export class HeroService {
// #docregion get-heroes-slowly // #docregion get-heroes-slowly
getHeroesSlowly(): Promise<Hero[]> { getHeroesSlowly(): Promise<Hero[]> {
return new Promise<Hero[]>(resolve => return new Promise<Hero[]>(resolve =>
setTimeout(() => resolve(HEROES), 2000) // 2 seconds setTimeout(resolve, 2000)) // delay 2 seconds
); .then(() => this.getHeroes());
} }
// #enddocregion get-heroes-slowly // #enddocregion get-heroes-slowly
// #docregion // #docregion

View File

@ -10,10 +10,9 @@ import 'mock_heroes.dart';
class HeroService { class HeroService {
Future<List<Hero>> getHeroes() async => mockHeroes; Future<List<Hero>> getHeroes() async => mockHeroes;
// See the "Take it slow" appendix
Future<List<Hero>> getHeroesSlowly() { Future<List<Hero>> getHeroesSlowly() {
return new Future<List<Hero>>.delayed( return new Future<List<Hero>>.delayed(
const Duration(seconds: 2), () => mockHeroes); const Duration(seconds: 2), getHeroes);
} }
// #docregion getHero // #docregion getHero

View File

@ -10,11 +10,10 @@ export class HeroService {
return Promise.resolve(HEROES); return Promise.resolve(HEROES);
} }
// See the "Take it slow" appendix
getHeroesSlowly(): Promise<Hero[]> { getHeroesSlowly(): Promise<Hero[]> {
return new Promise<Hero[]>(resolve => return new Promise<Hero[]>(resolve =>
setTimeout(() => resolve(HEROES), 2000) // 2 seconds setTimeout(resolve, 2000)) // delay 2 seconds
); .then(() => this.getHeroes());
} }
// #docregion getHero // #docregion getHero