Skip to content

Commit

Permalink
Refactor another ensure to try/finally
Browse files Browse the repository at this point in the history
  • Loading branch information
pittst3r committed Jul 14, 2020
1 parent a19a8a8 commit 53d8d60
Showing 1 changed file with 13 additions and 16 deletions.
29 changes: 13 additions & 16 deletions packages/bundler/src/bundler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,24 +70,21 @@ export class Bundler implements Subscribable<BundlerMessage, undefined> {
let bundler = new Bundler();

return yield resource(bundler, function*() {
let rollup: RollupWatcher | null = null;
let rollup: RollupWatcher = watch(prepareRollupOptions(bundles));;

yield ensure(() => {
if (rollup) {
rollup.close();
}
});
try {
let events: ChainableSubscription<Array<RollupWatcherEvent>, undefined> = yield subscribe(on<Array<RollupWatcherEvent>>(rollup, 'event'));
let messages = events
.map(([event]) => event)
.filter(event => event.code === 'END' || event.code === 'ERROR')
.map(event => event.code === 'ERROR' ? { type: 'error', error: event.error } : { type: 'update' });

rollup = watch(prepareRollupOptions(bundles));
let events: ChainableSubscription<Array<RollupWatcherEvent>, undefined> = yield subscribe(on<Array<RollupWatcherEvent>>(rollup, 'event'));
let messages = events
.map(([event]) => event)
.filter(event => event.code === 'END' || event.code === 'ERROR')
.map(event => event.code === 'ERROR' ? { type: 'error', error: event.error } : { type: 'update' });

yield messages.forEach(function*(message) {
bundler.channel.send(message as BundlerMessage);
});
yield messages.forEach(function*(message) {
bundler.channel.send(message as BundlerMessage);
});
} finally {
rollup.close();
}
});
}

Expand Down

0 comments on commit 53d8d60

Please sign in to comment.