Skip to content

Commit

Permalink
[TEST] fix some flappers that are sensitive to machine load
Browse files Browse the repository at this point in the history
  • Loading branch information
aricart committed May 12, 2023
1 parent 5e71814 commit bba8427
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 211 deletions.
6 changes: 3 additions & 3 deletions jetstream.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ Messages are replayed from a stream by _consumers_. A consumer configuration
specifies which messages should be presented. For example a consumer may only be
interested in viewing messages from a specific sequence or starting from a
specific time, or having a specific subject. The configuration also specifies if
the server should require messages to be acknowledged and how long to wait
for acknowledgements. The consumer configuration also specifies options to
control the rate at which messages are presented to the client.
the server should require messages to be acknowledged and how long to wait for
acknowledgements. The consumer configuration also specifies options to control
the rate at which messages are presented to the client.

For more information about JetStream, please visit the
[JetStream repo](https://github.com/nats-io/jetstream).
Expand Down
10 changes: 10 additions & 0 deletions nats-base-client/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,16 @@ export function delay(ms = 0): Promise<void> {
});
}

export function deadline<T>(p: Promise<T>, millis = 1000): Promise<T> {
const err = new Error(`deadline exceeded`);
const d = deferred<never>();
const timer = setTimeout(
() => d.reject(err),
millis,
);
return Promise.race([p, d]).finally(() => clearTimeout(timer));
}

export interface Deferred<T> extends Promise<T> {
/**
* Resolves the Deferred to a value T
Expand Down
Loading

0 comments on commit bba8427

Please sign in to comment.