Skip to content

Commit

Permalink
move timers map to be declared within HOF closure
Browse files Browse the repository at this point in the history
  • Loading branch information
dallen4 committed Dec 15, 2023
1 parent df2af36 commit e234cd5
Show file tree
Hide file tree
Showing 7 changed files with 2 additions and 11 deletions.
2 changes: 0 additions & 2 deletions cli/actions/drop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ type DropOptions = {

export const drop = async (input: string | undefined, options: DropOptions) => {
const ctx = initDropContext();
const timers = new Map<MessageType, NodeJS.Timeout>();

let currState = dropMachine.initialState;

Expand All @@ -32,7 +31,6 @@ export const drop = async (input: string | undefined, options: DropOptions) => {

const { init, stagePayload } = createDropHandlers({
ctx,
timers,
sendEvent,
logger: {
info: logInfo,
Expand Down
2 changes: 0 additions & 2 deletions cli/actions/grab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { DropContext } from '@shared/types/drop';

export const grab = async (id: string) => {
const ctx = initGrabContext();
const timers = new Map<MessageType, NodeJS.Timeout>();

let currState = grabMachine.initialState;

Expand All @@ -30,7 +29,6 @@ export const grab = async (id: string) => {

const { init } = createGrabHandlers({
ctx,
timers,
sendEvent,
logger: {
info: logInfo,
Expand Down
2 changes: 1 addition & 1 deletion shared/handlers/drop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import { DROP_API_PATH } from '../config/paths';

export const createDropHandlers = <FileType extends string | File = string>({
ctx,
timers,
sendEvent,
logger,
file,
Expand All @@ -42,6 +41,7 @@ export const createDropHandlers = <FileType extends string | File = string>({
initPeer,
}: DropHandlerInputs<FileType>) => {
const dropApiUrl = apiUri + DROP_API_PATH;
const timers = new Map<MessageType, NodeJS.Timeout>();

const clearTimer = (msgType: MessageType) => {
const timerId = timers.get(msgType);
Expand Down
2 changes: 1 addition & 1 deletion shared/handlers/grab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import { withMessageLock } from '../lib/messages';

export const createGrabHandlers = <FileType extends string | File = string>({
ctx,
timers,
sendEvent,
logger,
file,
Expand All @@ -40,6 +39,7 @@ export const createGrabHandlers = <FileType extends string | File = string>({
onRetryExceeded,
}: GrabHandlerInputs<FileType>) => {
const dropApiUrl = apiUri + DROP_API_PATH;
const timers = new Map<MessageType, NodeJS.Timeout>();

const clearTimer = (msgType: MessageType) => {
const timerId = timers.get(msgType);
Expand Down
1 change: 0 additions & 1 deletion shared/types/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ export type HashFile<InputType = string> = (

export type BaseHandlerInputs<Context, Event> = {
ctx: Context;
timers: Map<MessageType, NodeJS.Timeout>;
sendEvent: (event: Event) => unknown;
logger: {
info: (message: string) => void;
Expand Down
2 changes: 0 additions & 2 deletions web/hooks/use-drop.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import { cleanupSession } from 'lib/session';
export const useDrop = () => {
const logsRef = useRef<Array<string>>([]);
const contextRef = useRef<DropContext>(initDropContext());
const timersRef = useRef(new Map<MessageType, NodeJS.Timeout>());

const [{ value: state }, send] = useMachine(dropMachine);

Expand All @@ -38,7 +37,6 @@ export const useDrop = () => {
() =>
createDropHandlers({
ctx: contextRef.current,
timers: timersRef.current,
sendEvent: send,
logger: {
info: pushLog,
Expand Down
2 changes: 0 additions & 2 deletions web/hooks/use-grab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ export const useGrab = () => {

const logsRef = useRef<Array<string>>([]);
const contextRef = useRef<GrabContext>(initGrabContext());
const timersRef = useRef(new Map<MessageType, NodeJS.Timeout>());

const [{ value: state }, send] = useMachine(grabMachine);

Expand All @@ -35,7 +34,6 @@ export const useGrab = () => {
() =>
createGrabHandlers<File>({
ctx: contextRef.current,
timers: timersRef.current,
sendEvent: send,
logger: {
info: pushLog,
Expand Down

0 comments on commit e234cd5

Please sign in to comment.