TypeScript
Destructuring with Promise.all()

by Benny Neugebauer

this.save(primaryKey, bundle)
.then((cacheKey: string) => {
  return Promise.all([cacheKey, this.startTimer(cacheKey, ttl)]);
})
.then((result: [string, Bundle]) => {
  return this.saveInCache(result[0], result[1]);
});

this.save(primaryKey, bundle)
.then((cacheKey: string) => {
  return Promise.all([cacheKey, this.startTimer(cacheKey, ttl)]);
})
.then(([cacheKey, bundle]: [string, Bundle]) => {
  return this.saveInCache(cacheKey, bundle);
});

Red corner is not destructured ;)

Florian Keller

Sign in to comment!