use a class for the fake signal instead
Signed-off-by: Fredrik Adelöw <freben@gmail.com>
This commit is contained in:
@@ -18,34 +18,32 @@ import { Context } from './types';
|
||||
|
||||
/**
|
||||
* Since the root context can never abort, and since nobody is ever meant to
|
||||
* dispatch events through it, we can use a static fake instance for
|
||||
* efficiency.
|
||||
* dispatch events through it, we can use a static fake instance for efficiency.
|
||||
*
|
||||
* The reason that this was initially made for the root context is that due to
|
||||
* the way that we always chain contexts off of it, sometimes a huge number of
|
||||
* listeners want to add themselves to something that effectively never can be
|
||||
* aborted in the first place. This triggered warnings that the max listeners
|
||||
* limit was exceeded.
|
||||
*/
|
||||
const fakeAbortController = new AbortController();
|
||||
const fakeAbortSignal: AbortSignal = Object.freeze(
|
||||
Object.assign(
|
||||
{
|
||||
aborted: false,
|
||||
reason: undefined,
|
||||
throwIfAborted() {},
|
||||
onabort() {},
|
||||
addEventListener() {},
|
||||
removeEventListener() {},
|
||||
dispatchEvent() {
|
||||
return true;
|
||||
},
|
||||
},
|
||||
fakeAbortController.signal,
|
||||
),
|
||||
);
|
||||
class FakeAbortSignal implements AbortSignal {
|
||||
readonly aborted = false;
|
||||
readonly reason = undefined;
|
||||
onabort() {}
|
||||
throwIfAborted() {}
|
||||
addEventListener() {}
|
||||
removeEventListener() {}
|
||||
dispatchEvent() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* An empty root context.
|
||||
*/
|
||||
export class RootContext implements Context {
|
||||
readonly abortSignal = fakeAbortSignal;
|
||||
readonly abortSignal = new FakeAbortSignal();
|
||||
readonly deadline = undefined;
|
||||
|
||||
value<T = unknown>(_key: string): T | undefined {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ import { delegateAbortController, nowPlus, sleep, validateId } from './util';
|
||||
|
||||
class KnexBuilder {
|
||||
public build(client: string): Knex {
|
||||
return knexFactory({ client });
|
||||
return knexFactory({ client, useNullAsDefault: true });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user