Skip to content

Commit

Permalink
fix(animegarden): extract get client
Browse files Browse the repository at this point in the history
  • Loading branch information
yjl9903 committed Nov 20, 2023
1 parent 6a96f61 commit 5ff9d69
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
30 changes: 16 additions & 14 deletions packages/animegarden/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,24 @@ export interface AnimeGardenOptions extends PluginEntry {
provider?: DownloadProviders;
}

const memoClient = memo(
(provider: DownloadProviders, system: AnimeSystem, options: any) => {
const client = makeClient(provider, system, options);
onDeath(async () => {
await client.close();
});
return client;
},
{
serialize() {
return [];
}
}
);

export function AnimeGarden(options: AnimeGardenOptions): Plugin {
const provider = options.provider ?? 'webtorrent';
const getClient = memo(
(system: AnimeSystem) => {
const client = makeClient(provider, system, options);
onDeath(async () => {
await client.close();
});
return client;
},
{
serialize(system) {
return [];
}
}
);
const getClient = (sys: AnimeSystem) => memoClient(provider, sys, options);

let shouldClearCache = false;

Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/system/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ function registerApp(system: AnimeSystem, app: Breadc<{}>) {
// Refresh system
let sys = system;
const refresh = async () => {
const cancell = registerDeath(sys);
const cancel = registerDeath(sys);
try {
sys.printSpace();
if (options.introspect) {
Expand All @@ -110,7 +110,7 @@ function registerApp(system: AnimeSystem, app: Breadc<{}>) {

sys = await makeSystem();
sys.logger.log('');
cancell();
cancel();
}
};
await loop(refresh, options.duration);
Expand Down

0 comments on commit 5ff9d69

Please sign in to comment.