// Returns a promise of name by simulating an asynchronous call with a time-out. public Promise<String> getName() { final Deferred<String> d = q.defer(); Timer timer = new Timer() { @Override public void run() { d.progress(new TimerProgress("Loaded name", this)); d.resolve("World"); } }; d.progress(new TimerProgress("Loading name...", timer)); timer.schedule(500); return d.promise(); }
// Returns a promise of salutation by simulating an asynchronous call with a time-out. public Promise<String> getSalutation() { final Deferred<String> d = q.defer(); Timer timer = new Timer() { @Override public void run() { d.progress(new TimerProgress("Loaded salutation", this)); d.resolve("Hello"); } }; d.progress(new TimerProgress("Loading salutation...", timer)); timer.schedule(1000); return d.promise(); }