Skip to content

Commit b12dfdf

Browse files
trivikrsrchase
authored andcommitted
chore: reintroduce client.send overloads with callbacks (#463)
This reverts commit 60105ee5792aebbfa78a6b1a84714f881ed98be7.
1 parent 9cdf8e2 commit b12dfdf

File tree

2 files changed

+56
-2
lines changed

2 files changed

+56
-2
lines changed

packages/smithy-client/src/client.ts

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,44 @@ export class Client<
3636
SmithyResolvedConfiguration<HandlerOptions>
3737
>,
3838
options?: HandlerOptions
39-
): Promise<OutputType> {
39+
): Promise<OutputType>;
40+
send<InputType extends ClientInput, OutputType extends ClientOutput>(
41+
command: Command<
42+
ClientInput,
43+
InputType,
44+
ClientOutput,
45+
OutputType,
46+
SmithyResolvedConfiguration<HandlerOptions>
47+
>,
48+
options: HandlerOptions,
49+
cb: (err: any, data?: OutputType) => void
50+
): void;
51+
send<InputType extends ClientInput, OutputType extends ClientOutput>(
52+
command: Command<
53+
ClientInput,
54+
InputType,
55+
ClientOutput,
56+
OutputType,
57+
SmithyResolvedConfiguration<HandlerOptions>
58+
>,
59+
options?: HandlerOptions,
60+
cb?: (err: any, data?: OutputType) => void
61+
): Promise<OutputType> | void {
4062
const handler = command.resolveMiddleware(
4163
this.middlewareStack as any,
4264
this.config,
4365
options
4466
);
45-
return handler(command).then(result => result.output);
67+
if (cb) {
68+
handler(command)
69+
.then(result => cb(null, result.output), (err: any) => cb(err))
70+
.catch(
71+
// prevent any errors thrown in the callback from triggering an
72+
// unhandled promise rejection
73+
() => {}
74+
);
75+
} else {
76+
return handler(command).then(result => result.output);
77+
}
4678
}
4779
}

packages/types/src/client.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,28 @@ interface InvokeFunction<
2020
>,
2121
options?: any
2222
): Promise<OutputType>;
23+
<InputType extends InputTypes, OutputType extends OutputTypes>(
24+
command: Command<
25+
InputTypes,
26+
InputType,
27+
OutputTypes,
28+
OutputType,
29+
ResolvedClientConfiguration
30+
>,
31+
options: any,
32+
cb: (err: any, data?: OutputType) => void
33+
): void;
34+
<InputType extends InputTypes, OutputType extends OutputTypes>(
35+
command: Command<
36+
InputTypes,
37+
InputType,
38+
OutputTypes,
39+
OutputType,
40+
ResolvedClientConfiguration
41+
>,
42+
options?: any,
43+
cb?: (err: any, data?: OutputType) => void
44+
): Promise<OutputType> | void;
2345
}
2446

2547
/**

0 commit comments

Comments
 (0)