refactor: move locks into StreamController
This commit is contained in:
parent
4d05ac859f
commit
e109637e48
1 changed files with 5 additions and 5 deletions
|
|
@ -5,8 +5,6 @@ import winston from 'winston';
|
|||
import { Source } from '../source';
|
||||
import { contextFromRequestAndResponse, envIsProd, Id, ImdbId, StreamResolver, TmdbId } from '../utils';
|
||||
|
||||
const locks = new Map<string, Mutex>();
|
||||
|
||||
export class StreamController {
|
||||
public readonly router: Router;
|
||||
|
||||
|
|
@ -14,6 +12,8 @@ export class StreamController {
|
|||
private readonly sources: Source[];
|
||||
private readonly streamResolver: StreamResolver;
|
||||
|
||||
private readonly locks = new Map<string, Mutex>();
|
||||
|
||||
public constructor(logger: winston.Logger, sources: Source[], streams: StreamResolver) {
|
||||
this.router = Router();
|
||||
|
||||
|
|
@ -44,10 +44,10 @@ export class StreamController {
|
|||
|
||||
const sources = this.sources.filter(source => source.countryCodes.filter(countryCode => countryCode in ctx.config).length);
|
||||
|
||||
let mutex = locks.get(rawId);
|
||||
let mutex = this.locks.get(rawId);
|
||||
if (!mutex) {
|
||||
mutex = new Mutex();
|
||||
locks.set(rawId, mutex);
|
||||
this.locks.set(rawId, mutex);
|
||||
}
|
||||
|
||||
await mutex.runExclusive(async () => {
|
||||
|
|
@ -62,7 +62,7 @@ export class StreamController {
|
|||
});
|
||||
|
||||
if (!mutex.isLocked()) {
|
||||
locks.delete(rawId);
|
||||
this.locks.delete(rawId);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue