Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

module tweaks #59

Merged
merged 5 commits into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions core/deno.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nats-io/nats-core",
"version": "3.0.0-26",
"version": "3.0.0-27",
"exports": {
".": "./src/mod.ts",
"./internal": "./src/internal_mod.ts"
Expand Down Expand Up @@ -38,4 +38,4 @@
"@nats-io/nkeys": "jsr:@nats-io/[email protected]",
"@nats-io/nuid": "jsr:@nats-io/[email protected]"
}
}
}
4 changes: 2 additions & 2 deletions core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nats-io/nats-core",
"version": "3.0.0-26",
"version": "3.0.0-27",
"files": [
"lib/",
"LICENSE",
Expand Down Expand Up @@ -41,4 +41,4 @@
"typedoc": "^0.26.5",
"typescript": "^5.5.4"
}
}
}
1 change: 0 additions & 1 deletion core/src/internal_mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ export type { Transport, TransportFactory } from "./transport.ts";
export { Connect, INFO, ProtocolHandler } from "./protocol.ts";
export type {
Backoff,
Cancelable,
Deferred,
Delay,
ErrorResult,
Expand Down
1 change: 0 additions & 1 deletion core/src/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ export type {
Authenticator,
Backoff,
BenchOpts,
Cancelable,
Codec,
ConnectionOptions,
Deferred,
Expand Down
9 changes: 3 additions & 6 deletions core/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,7 @@ export function render(frame: Uint8Array): string {
.replace(/\r/g, cr);
}

export interface Cancelable {
cancel: () => void;
}

export interface Timeout<T> extends Promise<T>, Cancelable {
export interface Timeout<T> extends Promise<T> {
cancel: () => void;
}

Expand Down Expand Up @@ -94,7 +90,7 @@ export function timeout<T>(ms: number, asyncTraces = true): Timeout<T> {
return Object.assign(p, methods) as Timeout<T>;
}

export interface Delay extends Promise<void>, Cancelable {
export interface Delay extends Promise<void> {
cancel: () => void;
}

Expand All @@ -107,6 +103,7 @@ export function delay(ms = 0): Delay {
const cancel = (): void => {
if (timer) {
clearTimeout(timer);
resolve();
}
};
methods = { cancel };
Expand Down
2 changes: 1 addition & 1 deletion core/src/version.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
// This file is generated - do not edit
export const version = "3.0.0-26";
export const version = "3.0.0-27";
2 changes: 1 addition & 1 deletion deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"test_helpers": "./test_helpers/mod.ts"
},
"tasks": {
"clean": "rm -Rf ./coverage core/lib jetstream/lib services/lib kv/lib obj/lib transport-node/lib transport-ws/lib",
"clean": "rm -Rf ./coverage core/lib core/build jetstream/lib jetstream/build services/lib services/build kv/lib kv/build obj/lib obj/build transport-node/lib transport-ws/lib",
"test": "deno task clean && deno task lint && deno task test-all",
"test-all": "deno task test-core && deno task test-jetstream && deno task test-kv && deno task test-obj && deno task test-services && deno task test-unsafe",
"test-unsafe": "deno test -A --parallel --reload --quiet --unsafely-ignore-certificate-errors --coverage=coverage core/unsafe_tests",
Expand Down
6 changes: 3 additions & 3 deletions jetstream/deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@
]
},
"tasks": {
"test": "deno test -A --parallel --reload --quiet tests/ --import-map=import_map.json"
"test": "deno test -A --parallel --reload --trace-leaks --quiet tests/ --import-map=import_map.json"
},
"imports": {
"@nats-io/nats-core": "jsr:@nats-io/nats-core@~3.0.0-26"
"@nats-io/nats-core": "jsr:@nats-io/nats-core@~3.0.0-27"
}
}
}
4 changes: 2 additions & 2 deletions jetstream/examples/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
*/

import { createConsumer, fill, initStream } from "../tests/jstest_util.ts";
import type { NatsConnection } from "jsr:@nats-io/[email protected]17";
import { nuid } from "jsr:@nats-io/[email protected]17";
import type { NatsConnection } from "jsr:@nats-io/[email protected]27";
import { nuid } from "jsr:@nats-io/[email protected]27";

export async function setupStreamAndConsumer(
nc: NatsConnection,
Expand Down
6 changes: 3 additions & 3 deletions jetstream/import_map.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
"imports": {
"@nats-io/nkeys": "jsr:@nats-io/[email protected]",
"@nats-io/nuid": "jsr:@nats-io/[email protected]",
"@nats-io/nats-core": "jsr:@nats-io/nats-core@~3.0.0-26",
"@nats-io/nats-core/internal": "jsr:@nats-io/nats-core@~3.0.0-26/internal",
"@nats-io/nats-core": "jsr:@nats-io/nats-core@~3.0.0-27",
"@nats-io/nats-core/internal": "jsr:@nats-io/nats-core@~3.0.0-27/internal",
"test_helpers": "../test_helpers/mod.ts",
"@std/io": "jsr:@std/[email protected]"
}
}
}
4 changes: 2 additions & 2 deletions jetstream/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@
},
"description": "jetstream library - this library implements all the base functionality for NATS JetStream for javascript clients",
"dependencies": {
"@nats-io/nats-core": "~3.0.0-26"
"@nats-io/nats-core": "~3.0.0-27"
},
"devDependencies": {
"@types/node": "^22.0.0",
"shx": "^0.3.4",
"typedoc": "^0.26.5",
"typescript": "^5.5.4"
}
}
}
26 changes: 21 additions & 5 deletions jetstream/src/pushconsumer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
} from "@nats-io/nats-core/internal";
import type {
CallbackFn,
Delay,
QueuedIterator,
Status,
Subscription,
Expand All @@ -49,6 +50,7 @@ export class PushConsumerMessagesImpl extends QueuedIteratorImpl<JsMsg>
serial: number;
createFails!: number;
statusIterator!: QueuedIteratorImpl<Status>;
cancelables: Delay[];

constructor(
c: PushConsumerImpl,
Expand All @@ -59,6 +61,7 @@ export class PushConsumerMessagesImpl extends QueuedIteratorImpl<JsMsg>
this.consumer = c;
this.monitor = null;
this.listeners = [];
this.cancelables = [];
this.abortOnMissingResource =
userOptions.abort_on_missing_resource === true;
this.callback = userOptions.callback || null;
Expand Down Expand Up @@ -119,12 +122,20 @@ export class PushConsumerMessagesImpl extends QueuedIteratorImpl<JsMsg>
this.stop(err);
}
const bo = backoff();
delay(bo.backoff(this.createFails))
.then(() => {
if (!this.done) {
this.reset();
}
const c = delay(bo.backoff(this.createFails));
c.then(() => {
const idx = this.cancelables.indexOf(c);
if (idx !== -1) {
this.cancelables = this.cancelables.splice(idx, idx);
}
if (!this.done) {
this.reset();
}
})
.catch((_) => {
// canceled
});
this.cancelables.push(c);
});
}

Expand Down Expand Up @@ -161,6 +172,11 @@ export class PushConsumerMessagesImpl extends QueuedIteratorImpl<JsMsg>
this.statusIterator?.stop();
this.monitor?.cancel();
this.monitor = null;
// if we have delays, stop them
this.cancelables.forEach((c) => {
c.cancel();
});
this.cancelables = [];
this._push(() => {
super.stop(err);
this.listeners.forEach((n) => {
Expand Down
6 changes: 2 additions & 4 deletions jetstream/tests/pushconsumers_ordered_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import {
jetstreamServerConf,
notCompatible,
} from "test_helpers";
import { deferred } from "@nats-io/nats-core";
import type {
PushConsumerImpl,
PushConsumerMessagesImpl,
Expand Down Expand Up @@ -74,7 +73,6 @@ Deno.test("ordered push consumers - consume reset", async () => {
assertExists(oc);

const seen: number[] = new Array(3).fill(0);
const done = deferred();

const iter = await oc.consume({
callback: (m: JsMsg) => {
Expand All @@ -87,11 +85,10 @@ Deno.test("ordered push consumers - consume reset", async () => {
}
if (m.info.pending === 0) {
iter.stop();
done.resolve();
}
},
}) as PushConsumerMessagesImpl;
await done;
await iter.closed();

assertEquals(seen, [2, 2, 1]);
assertEquals(oc.serial, 3);
Expand Down Expand Up @@ -151,6 +148,7 @@ Deno.test("ordered push consumers - filters consume", async () => {
}
}

await iter.closed();
assertEquals(iter.getProcessed(), 1);

await cleanup(ns, nc);
Expand Down
4 changes: 2 additions & 2 deletions kv/deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"test": "deno test -A --parallel --reload --quiet tests/ --import-map=import_map.json"
},
"imports": {
"@nats-io/nats-core": "jsr:@nats-io/nats-core@~3.0.0-26",
"@nats-io/nats-core": "jsr:@nats-io/nats-core@~3.0.0-27",
"@nats-io/jetstream": "jsr:@nats-io/jetstream@~3.0.0-10"
}
}
}
6 changes: 3 additions & 3 deletions kv/import_map.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"imports": {
"@nats-io/nats-core": "jsr:@nats-io/nats-core@~3.0.0-26",
"@nats-io/nats-core/internal": "jsr:@nats-io/nats-core@~3.0.0-26/internal",
"@nats-io/nats-core": "jsr:@nats-io/nats-core@~3.0.0-27",
"@nats-io/nats-core/internal": "jsr:@nats-io/nats-core@~3.0.0-27/internal",
"@nats-io/jetstream": "jsr:@nats-io/jetstream@~3.0.0-10",
"@nats-io/jetstream/internal": "jsr:@nats-io/jetstream@~3.0.0-10/internal",
"test_helpers": "../test_helpers/mod.ts",
"@nats-io/nkeys": "jsr:@nats-io/[email protected]",
"@nats-io/nuid": "jsr:@nats-io/[email protected]",
"@std/io": "jsr:@std/[email protected]"
}
}
}
4 changes: 2 additions & 2 deletions kv/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@
"description": "kv library - this library implements all the base functionality for NATS KV javascript clients",
"dependencies": {
"@nats-io/jetstream": "~3.0.0-10",
"@nats-io/nats-core": "~3.0.0-26"
"@nats-io/nats-core": "~3.0.0-27"
},
"devDependencies": {
"@types/node": "^22.0.0",
"shx": "^0.3.4",
"typedoc": "^0.26.5",
"typescript": "^5.5.4"
}
}
}
4 changes: 2 additions & 2 deletions obj/deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"test": "deno test -A --parallel --reload --quiet tests/ --import-map=import_map.json"
},
"imports": {
"@nats-io/nats-core": "jsr:@nats-io/nats-core@~3.0.0-26",
"@nats-io/nats-core": "jsr:@nats-io/nats-core@~3.0.0-27",
"@nats-io/jetstream": "jsr:@nats-io/jetstream@~3.0.0-10"
}
}
}
6 changes: 3 additions & 3 deletions obj/import_map.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"imports": {
"@nats-io/nats-core": "jsr:@nats-io/nats-core@~3.0.0-26",
"@nats-io/nats-core/internal": "jsr:@nats-io/nats-core@~3.0.0-26/internal",
"@nats-io/nats-core": "jsr:@nats-io/nats-core@~3.0.0-27",
"@nats-io/nats-core/internal": "jsr:@nats-io/nats-core@~3.0.0-27/internal",
"@nats-io/jetstream": "jsr:@nats-io/jetstream@~3.0.0-10",
"@nats-io/jetstream/internal": "jsr:@nats-io/jetstream@~3.0.0-10/internal",
"test_helpers": "../test_helpers/mod.ts",
"@nats-io/nkeys": "jsr:@nats-io/[email protected]",
"@nats-io/nuid": "jsr:@nats-io/[email protected]",
"@std/io": "jsr:@std/[email protected]"
}
}
}
4 changes: 2 additions & 2 deletions obj/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@
"description": "obj library - this library implements all the base functionality for NATS objectstore for javascript clients",
"dependencies": {
"@nats-io/jetstream": "~3.0.0-10",
"@nats-io/nats-core": "~3.0.0-26"
"@nats-io/nats-core": "~3.0.0-27"
},
"devDependencies": {
"@types/node": "^22.0.0",
"shx": "^0.3.4",
"typedoc": "^0.26.5",
"typescript": "^5.5.4"
}
}
}
4 changes: 2 additions & 2 deletions services/deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@
"test": "deno test -A --parallel --reload --quiet tests/ --import-map=import_map.json"
},
"imports": {
"@nats-io/nats-core": "jsr:@nats-io/nats-core@~3.0.0-26"
"@nats-io/nats-core": "jsr:@nats-io/nats-core@~3.0.0-27"
}
}
}
6 changes: 3 additions & 3 deletions services/import_map.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"imports": {
"@nats-io/nats-core": "jsr:@nats-io/nats-core@~3.0.0-26",
"@nats-io/nats-core/internal": "jsr:@nats-io/nats-core@~3.0.0-26/internal",
"@nats-io/nats-core": "jsr:@nats-io/nats-core@~3.0.0-27",
"@nats-io/nats-core/internal": "jsr:@nats-io/nats-core@~3.0.0-27/internal",
"test_helpers": "../test_helpers/mod.ts",
"@nats-io/nkeys": "jsr:@nats-io/[email protected]",
"@nats-io/nuid": "jsr:@nats-io/[email protected]",
"@std/io": "jsr:@std/[email protected]"
}
}
}
4 changes: 2 additions & 2 deletions services/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@
},
"description": "services library - this library implements all the base functionality for NATS services for javascript clients",
"dependencies": {
"@nats-io/nats-core": "~3.0.0-26"
"@nats-io/nats-core": "~3.0.0-27"
},
"devDependencies": {
"@types/node": "^22.0.0",
"shx": "^0.3.4",
"typedoc": "^0.26.5",
"typescript": "^5.5.4"
}
}
}
4 changes: 2 additions & 2 deletions transport-deno/deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
},
"imports": {
"@std/io": "jsr:@std/[email protected]",
"@nats-io/nats-core": "jsr:@nats-io/nats-core@~3.0.0-26",
"@nats-io/nats-core": "jsr:@nats-io/nats-core@~3.0.0-27",
"@nats-io/nkeys": "jsr:@nats-io/[email protected]",
"@nats-io/nuid": "jsr:@nats-io/[email protected]"
}
}
}
1 change: 1 addition & 0 deletions transport-node/examples/bench.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
const parse = require("minimist");
const { Nuid, connect } = require("../index");
const { Bench, Metric } = require("../lib/nats-base-client/bench");
const { process } = require("node:process");

const defaults = {
s: "127.0.0.1:4222",
Expand Down
1 change: 1 addition & 0 deletions transport-node/examples/nats-events.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env node

const { process } = require("node:process");
const parse = require("minimist");
const { connect } = require("../index");

Expand Down
Loading