Skip to content

Commit

Permalink
Add NewSubscriber Symbol on Subscriber to hide creation from user
Browse files Browse the repository at this point in the history
  • Loading branch information
Charles-Schleich committed Oct 24, 2024
1 parent d8d358f commit 198f2c4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
7 changes: 4 additions & 3 deletions zenoh-ts/src/pubsub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import { Encoding, IntoEncoding } from "./encoding";
// ███████ ██████ ██████ ███████ ██████ ██ ██ ██ ██████ ███████ ██ ██


export const NewSubscriber = Symbol();
/**
* Class to represent a Subscriber on Zenoh,
* created via calling `declare_subscriber()` on a `session`
Expand Down Expand Up @@ -62,7 +63,7 @@ export class Subscriber {
/**
* @ignore
*/
constructor(
private constructor(
remote_subscriber: RemoteSubscriber,
callback_subscriber: boolean,
) {
Expand Down Expand Up @@ -109,10 +110,10 @@ export class Subscriber {
* please use `declare_subscriber` on a session to create a subscriber
* @ignore
*/
static async new(
static [NewSubscriber](
remote_subscriber: RemoteSubscriber,
callback_subscriber: boolean,
): Promise<Subscriber> {
): Subscriber {
return new Subscriber(remote_subscriber, callback_subscriber);
}
}
Expand Down
7 changes: 4 additions & 3 deletions zenoh-ts/src/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import {
Selector,
} from "./query";
import { SimpleChannel } from "channel-ts";
import { ChannelType, FifoChannel, Handler, Publisher, RingChannel, Subscriber } from "./pubsub";
import { ChannelType, FifoChannel, Handler, NewSubscriber, Publisher, RingChannel, Subscriber } from "./pubsub";
import {
priority_to_int,
congestion_control_to_int,
Expand Down Expand Up @@ -417,11 +417,12 @@ export class Session {
handler_type,
);
}

let subscriber = await Subscriber.new(
let subscriber = Subscriber[NewSubscriber](
remote_subscriber,
callback_subscriber,
);

return subscriber;
}

Expand Down

0 comments on commit 198f2c4

Please sign in to comment.