mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-15 19:13:31 +01:00
refactor: use eslint-config-neon for packages. (#8579)
Co-authored-by: Noel <buechler.noel@outlook.com>
This commit is contained in:
@@ -5,7 +5,7 @@ import type { SessionInfo, WebSocketManager, WebSocketManagerOptions } from '../
|
||||
export interface FetchingStrategyOptions
|
||||
extends Omit<
|
||||
WebSocketManagerOptions,
|
||||
'retrieveSessionInfo' | 'updateSessionInfo' | 'shardCount' | 'shardIds' | 'rest'
|
||||
'rest' | 'retrieveSessionInfo' | 'shardCount' | 'shardIds' | 'updateSessionInfo'
|
||||
> {
|
||||
readonly gatewayInformation: APIGatewayBotInfo;
|
||||
readonly shardCount: number;
|
||||
@@ -16,11 +16,12 @@ export interface FetchingStrategyOptions
|
||||
*/
|
||||
export interface IContextFetchingStrategy {
|
||||
readonly options: FetchingStrategyOptions;
|
||||
retrieveSessionInfo: (shardId: number) => Awaitable<SessionInfo | null>;
|
||||
updateSessionInfo: (shardId: number, sessionInfo: SessionInfo | null) => Awaitable<void>;
|
||||
retrieveSessionInfo(shardId: number): Awaitable<SessionInfo | null>;
|
||||
updateSessionInfo(shardId: number, sessionInfo: SessionInfo | null): Awaitable<void>;
|
||||
}
|
||||
|
||||
export async function managerToFetchingStrategyOptions(manager: WebSocketManager): Promise<FetchingStrategyOptions> {
|
||||
// eslint-disable-next-line @typescript-eslint/unbound-method
|
||||
const { retrieveSessionInfo, updateSessionInfo, shardCount, shardIds, rest, ...managerOptions } = manager.options;
|
||||
|
||||
return {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import type { FetchingStrategyOptions, IContextFetchingStrategy } from './IContextFetchingStrategy';
|
||||
import type { SessionInfo, WebSocketManager } from '../../ws/WebSocketManager';
|
||||
import type { SessionInfo, WebSocketManager } from '../../ws/WebSocketManager.js';
|
||||
import type { FetchingStrategyOptions, IContextFetchingStrategy } from './IContextFetchingStrategy.js';
|
||||
|
||||
export class SimpleContextFetchingStrategy implements IContextFetchingStrategy {
|
||||
public constructor(private readonly manager: WebSocketManager, public readonly options: FetchingStrategyOptions) {}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
import { isMainThread, parentPort } from 'node:worker_threads';
|
||||
import { Collection } from '@discordjs/collection';
|
||||
import type { FetchingStrategyOptions, IContextFetchingStrategy } from './IContextFetchingStrategy';
|
||||
import type { SessionInfo } from '../../ws/WebSocketManager';
|
||||
import type { SessionInfo } from '../../ws/WebSocketManager.js';
|
||||
import {
|
||||
WorkerRecievePayload,
|
||||
WorkerRecievePayloadOp,
|
||||
WorkerSendPayload,
|
||||
WorkerSendPayloadOp,
|
||||
} from '../sharding/WorkerShardingStrategy';
|
||||
type WorkerRecievePayload,
|
||||
type WorkerSendPayload,
|
||||
} from '../sharding/WorkerShardingStrategy.js';
|
||||
import type { FetchingStrategyOptions, IContextFetchingStrategy } from './IContextFetchingStrategy.js';
|
||||
|
||||
export class WorkerContextFetchingStrategy implements IContextFetchingStrategy {
|
||||
private readonly sessionPromises = new Collection<number, (session: SessionInfo | null) => void>();
|
||||
@@ -33,7 +33,9 @@ export class WorkerContextFetchingStrategy implements IContextFetchingStrategy {
|
||||
shardId,
|
||||
nonce,
|
||||
};
|
||||
// eslint-disable-next-line no-promise-executor-return
|
||||
const promise = new Promise<SessionInfo | null>((resolve) => this.sessionPromises.set(nonce, resolve));
|
||||
// eslint-disable-next-line unicorn/require-post-message-target-origin
|
||||
parentPort!.postMessage(payload);
|
||||
return promise;
|
||||
}
|
||||
@@ -44,6 +46,7 @@ export class WorkerContextFetchingStrategy implements IContextFetchingStrategy {
|
||||
shardId,
|
||||
session: sessionInfo,
|
||||
};
|
||||
// eslint-disable-next-line unicorn/require-post-message-target-origin
|
||||
parentPort!.postMessage(payload);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user