|
1 | 1 | import { getCurrentHub, initAndBind, Integrations as CoreIntegrations } from '@sentry/core'; |
2 | 2 | import { getMainCarrier, setHubOnCarrier } from '@sentry/hub'; |
3 | 3 | import { SessionStatus } from '@sentry/types'; |
4 | | -import { getGlobalObject } from '@sentry/utils'; |
| 4 | +import { getGlobalObject, logger } from '@sentry/utils'; |
5 | 5 | import * as domain from 'domain'; |
6 | 6 |
|
7 | 7 | import { NodeClient } from './client'; |
@@ -140,31 +140,37 @@ export function lastEventId(): string | undefined { |
140 | 140 | } |
141 | 141 |
|
142 | 142 | /** |
143 | | - * A promise that resolves when all current events have been sent. |
144 | | - * If you provide a timeout and the queue takes longer to drain the promise returns false. |
| 143 | + * Call `flush()` on the current client, if there is one. See {@link Client.flush}. |
145 | 144 | * |
146 | | - * @param timeout Maximum time in ms the client should wait. |
| 145 | + * @param timeout Maximum time in ms the client should wait to flush its event queue. Omitting this parameter will cause |
| 146 | + * the client to wait until all events are sent before resolving the promise. |
| 147 | + * @returns A promise which resolves to `true` if the queue successfully drains before the timeout, or `false` if it |
| 148 | + * doesn't (or if there's no client defined). |
147 | 149 | */ |
148 | 150 | export async function flush(timeout?: number): Promise<boolean> { |
149 | 151 | const client = getCurrentHub().getClient<NodeClient>(); |
150 | 152 | if (client) { |
151 | 153 | return client.flush(timeout); |
152 | 154 | } |
153 | | - return Promise.reject(false); |
| 155 | + logger.warn('Cannot flush events. No client defined.'); |
| 156 | + return Promise.resolve(false); |
154 | 157 | } |
155 | 158 |
|
156 | 159 | /** |
157 | | - * A promise that resolves when all current events have been sent. |
158 | | - * If you provide a timeout and the queue takes longer to drain the promise returns false. |
| 160 | + * Call `close()` on the current client, if there is one. See {@link Client.close}. |
159 | 161 | * |
160 | | - * @param timeout Maximum time in ms the client should wait. |
| 162 | + * @param timeout Maximum time in ms the client should wait to flush its event queue before shutting down. Omitting this |
| 163 | + * parameter will cause the client to wait until all events are sent before disabling itself. |
| 164 | + * @returns A promise which resolves to `true` if the queue successfully drains before the timeout, or `false` if it |
| 165 | + * doesn't (or if there's no client defined). |
161 | 166 | */ |
162 | 167 | export async function close(timeout?: number): Promise<boolean> { |
163 | 168 | const client = getCurrentHub().getClient<NodeClient>(); |
164 | 169 | if (client) { |
165 | 170 | return client.close(timeout); |
166 | 171 | } |
167 | | - return Promise.reject(false); |
| 172 | + logger.warn('Cannot flush events and disable SDK. No client defined.'); |
| 173 | + return Promise.resolve(false); |
168 | 174 | } |
169 | 175 |
|
170 | 176 | /** |
|
0 commit comments