Skip to content

Commit

Permalink
Use ensure() API in Bundler rather than try/catch
Browse files Browse the repository at this point in the history
  • Loading branch information
pittst3r committed Jul 12, 2020
1 parent b116f9c commit 7f1b18a
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions packages/bundler/src/bundler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Operation, resource } from 'effection';
import { on } from '@effection/events';
import { subscribe, Subscribable, SymbolSubscribable, ChainableSubscription } from '@effection/subscription';
import { Channel } from '@effection/channel';
import { ensure } from '@bigtest/effection';
import { watch, RollupWatchOptions, RollupWatcherEvent, RollupWatcher } from 'rollup';
import resolve from '@rollup/plugin-node-resolve';
import * as commonjs from '@rollup/plugin-commonjs';
Expand Down Expand Up @@ -71,22 +72,22 @@ export class Bundler implements Subscribable<BundlerMessage, undefined> {
return yield resource(bundler, function*() {
let rollup: RollupWatcher | null = null;

try {
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);
});
} finally {
yield ensure(() => {
if (rollup) {
rollup.close();
}
}
});

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);
});
});
}

Expand Down

0 comments on commit 7f1b18a

Please sign in to comment.