Skip to content

Commit f079d84

Browse files
committed
feat: return promise on channel send
1 parent dfa1d65 commit f079d84

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

packages/core/realtime-js/src/RealtimeChannel.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,8 +266,18 @@ export default class RealtimeChannel {
266266
send(
267267
payload: { type: string; [key: string]: any },
268268
opts: { [key: string]: any } = {}
269-
): Push {
270-
return this.push(payload.type as any, payload, opts.timeout ?? this.timeout)
269+
): Promise<'ok' | 'timeout'> {
270+
const push = this.push(
271+
payload.type as any,
272+
payload,
273+
opts.timeout ?? this.timeout
274+
)
275+
276+
return new Promise((resolve) => {
277+
push
278+
.receive('ok', () => resolve('ok'))
279+
.receive('timeout', () => resolve('timeout'))
280+
})
271281
}
272282

273283
replyEventName(ref: string): string {

0 commit comments

Comments
 (0)