Skip to content

Commit f8c8590

Browse files
authored
fix(*): better timeout handling (#44)
1 parent cd4238c commit f8c8590

File tree

6 files changed

+41
-44
lines changed

6 files changed

+41
-44
lines changed

src/commands/create-channel.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
race,
1212
take,
1313
throwError,
14-
timer,
14+
timeout,
1515
} from 'rxjs';
1616

1717
export const createChannel = async (
@@ -30,6 +30,11 @@ export const createChannel = async (
3030
),
3131
take(1),
3232
map(channelState => channelState.channelId as number),
33+
timeout({
34+
first: CommandTimeout,
35+
with: () =>
36+
throwError(() => new CommandTimedOutError('createChannel')),
37+
}),
3338
),
3439
socket.packet.pipe(
3540
filterPacket(PermissionDenied),
@@ -38,11 +43,6 @@ export const createChannel = async (
3843
throwError(() => new PermissionDeniedError(permissionDenied)),
3944
),
4045
),
41-
timer(CommandTimeout).pipe(
42-
concatMap(() =>
43-
throwError(() => new CommandTimedOutError('createChannel')),
44-
),
45-
),
4646
),
4747
);
4848

src/commands/fetch-channel-permissions.ts

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,22 @@ import { CommandTimedOutError } from '@/errors';
33
import { MumbleSocket } from '@/mumble-socket';
44
import { filterPacket } from '@/rxjs-operators/filter-packet';
55
import { PermissionQuery } from '@tf2pickup-org/mumble-protocol';
6-
import {
7-
concatMap,
8-
filter,
9-
lastValueFrom,
10-
race,
11-
take,
12-
throwError,
13-
timer,
14-
} from 'rxjs';
6+
import { filter, lastValueFrom, take, throwError, timeout } from 'rxjs';
157

168
export const fetchChannelPermissions = async (
179
socket: MumbleSocket,
1810
channelId: number,
1911
): Promise<PermissionQuery> => {
2012
const ret = lastValueFrom(
21-
race(
22-
socket.packet.pipe(
23-
filterPacket(PermissionQuery),
24-
filter(permissionQuery => permissionQuery.channelId === channelId),
25-
take(1),
26-
),
27-
timer(CommandTimeout).pipe(
28-
concatMap(() =>
13+
socket.packet.pipe(
14+
filterPacket(PermissionQuery),
15+
filter(permissionQuery => permissionQuery.channelId === channelId),
16+
take(1),
17+
timeout({
18+
first: CommandTimeout,
19+
with: () =>
2920
throwError(() => new CommandTimedOutError('fetchChannelPermissions')),
30-
),
31-
),
21+
}),
3222
),
3323
);
3424

src/commands/link-channels.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
race,
1212
take,
1313
throwError,
14-
timer,
14+
timeout,
1515
} from 'rxjs';
1616

1717
export const linkChannels = async (
@@ -26,6 +26,11 @@ export const linkChannels = async (
2626
filter(channelSync => channelSync.channelId === channelId),
2727
take(1),
2828
map(() => void 0),
29+
timeout({
30+
first: CommandTimeout,
31+
with: () =>
32+
throwError(() => new CommandTimedOutError('linkChannels')),
33+
}),
2934
),
3035
socket.packet.pipe(
3136
filterPacket(PermissionDenied),
@@ -35,11 +40,6 @@ export const linkChannels = async (
3540
throwError(() => new PermissionDeniedError(permissionDenied)),
3641
),
3742
),
38-
timer(CommandTimeout).pipe(
39-
concatMap(() =>
40-
throwError(() => new CommandTimedOutError('linkChannels')),
41-
),
42-
),
4343
),
4444
);
4545
socket.send(

src/commands/move-user-to-channel.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { PermissionDeniedError } from '@/errors';
1+
import { CommandTimeout } from '@/config';
2+
import { CommandTimedOutError, PermissionDeniedError } from '@/errors';
23
import { MumbleSocket } from '@/mumble-socket';
34
import { filterPacket } from '@/rxjs-operators/filter-packet';
45
import { PermissionDenied, UserState } from '@tf2pickup-org/mumble-protocol';
@@ -10,6 +11,7 @@ import {
1011
race,
1112
take,
1213
throwError,
14+
timeout,
1315
} from 'rxjs';
1416

1517
export const moveUserToChannel = async (
@@ -28,6 +30,11 @@ export const moveUserToChannel = async (
2830
),
2931
take(1),
3032
map(() => void 0),
33+
timeout({
34+
first: CommandTimeout,
35+
with: () =>
36+
throwError(() => new CommandTimedOutError('moveUserToChannel')),
37+
}),
3138
),
3239
socket.packet.pipe(
3340
filterPacket(PermissionDenied),

src/commands/remove-channel.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
race,
1515
take,
1616
throwError,
17-
timer,
17+
timeout,
1818
} from 'rxjs';
1919

2020
export const removeChannel = async (
@@ -28,6 +28,11 @@ export const removeChannel = async (
2828
filter(channelRemove => channelRemove.channelId === channelId),
2929
take(1),
3030
map(channelRemove => channelRemove.channelId),
31+
timeout({
32+
first: CommandTimeout,
33+
with: () =>
34+
throwError(() => new CommandTimedOutError('removeChannel')),
35+
}),
3136
),
3237
socket.packet.pipe(
3338
filterPacket(PermissionDenied),
@@ -37,11 +42,6 @@ export const removeChannel = async (
3742
throwError(() => new PermissionDeniedError(permissionDenied)),
3843
),
3944
),
40-
timer(CommandTimeout).pipe(
41-
concatMap(() =>
42-
throwError(() => new CommandTimedOutError('removeChannel')),
43-
),
44-
),
4545
),
4646
);
4747
socket.send(ChannelRemove, ChannelRemove.create({ channelId }));

src/commands/unlink-channels.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
race,
1212
take,
1313
throwError,
14-
timer,
14+
timeout,
1515
} from 'rxjs';
1616

1717
export const unlinkChannels = async (
@@ -26,6 +26,11 @@ export const unlinkChannels = async (
2626
filter(channelSync => channelSync.channelId === channelId),
2727
take(1),
2828
map(() => void 0),
29+
timeout({
30+
first: CommandTimeout,
31+
with: () =>
32+
throwError(() => new CommandTimedOutError('unlinkChannels')),
33+
}),
2934
),
3035
socket.packet.pipe(
3136
filterPacket(PermissionDenied),
@@ -35,11 +40,6 @@ export const unlinkChannels = async (
3540
throwError(() => new PermissionDeniedError(permissionDenied)),
3641
),
3742
),
38-
timer(CommandTimeout).pipe(
39-
concatMap(() =>
40-
throwError(() => new CommandTimedOutError('linkChannels')),
41-
),
42-
),
4343
),
4444
);
4545
socket.send(

0 commit comments

Comments
 (0)