Skip to content

Commit

Permalink
Align async, remove unneccsary Async/Promis
Browse files Browse the repository at this point in the history
  • Loading branch information
Charles-Schleich committed Dec 16, 2024
1 parent 1180f72 commit 0e79698
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 24 deletions.
2 changes: 1 addition & 1 deletion zenoh-ts/examples/src/z_pong.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export async function main() {
);

const subscriber_callback = async function (sample: Sample): Promise<void> {
await pub.put(sample.payload());
pub.put(sample.payload());
};

await session.declare_subscriber("test/pong", subscriber_callback);
Expand Down
20 changes: 10 additions & 10 deletions zenoh-ts/src/remote_api/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ export class RemoteSession {
}

// get
async get(
get(
key_expr: string,
parameters: string | null,
handler: HandlerChannel,
Expand All @@ -179,7 +179,7 @@ export class RemoteSession {
payload?: Array<number>,
attachment?: Array<number>,
timeout_ms?: number,
): Promise<SimpleChannel<ReplyWS>> {
): SimpleChannel<ReplyWS> {
let uuid = uuidv4();
let channel: SimpleChannel<ReplyWS> = new SimpleChannel<ReplyWS>();
this.get_receiver.set(uuid, channel);
Expand Down Expand Up @@ -214,13 +214,13 @@ export class RemoteSession {
}

// delete
async delete(
delete(
key_expr: string,
congestion_control?: number,
priority?: number,
express?: boolean,
attachment?: Array<number>
): Promise<void> {
): void {
let owned_keyexpr: OwnedKeyExprWrapper = key_expr;
let opt_attachment = undefined;
if (attachment != undefined) {
Expand All @@ -244,11 +244,11 @@ export class RemoteSession {
this.ws.close();
}

async declare_remote_subscriber(
declare_remote_subscriber(
key_expr: string,
handler: HandlerChannel,
callback?: (sample: SampleWS) => Promise<void>,
): Promise<RemoteSubscriber> {
callback?: (sample: SampleWS) => void,
): RemoteSubscriber {
let uuid = uuidv4();

let control_message: ControlMsg = {
Expand Down Expand Up @@ -384,7 +384,7 @@ export class RemoteSession {
declare_liveliness_subscriber(
key_expr: string,
history: boolean,
callback?: (sample: SampleWS) => Promise<void>,
callback?: (sample: SampleWS) => void,
): RemoteSubscriber {
let uuid = uuidv4();

Expand Down Expand Up @@ -478,7 +478,7 @@ export class RemoteSession {
console.warn("Closed");
}

private async handle_control_message(control_msg: ControlMsg) {
private handle_control_message(control_msg: ControlMsg) {
if (typeof control_msg === "string") {
console.warn("unhandled Control Message:", control_msg);
} else if (typeof control_msg === "object") {
Expand All @@ -492,7 +492,7 @@ export class RemoteSession {
}
}

private async handle_data_message(data_msg: DataMsg) {
private handle_data_message(data_msg: DataMsg) {
if ("Sample" in data_msg) {
let subscription_uuid: UUIDv4 = data_msg["Sample"][1];

Expand Down
33 changes: 20 additions & 13 deletions zenoh-ts/src/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ export interface GetOptions {
payload?: IntoZBytes,
attachment?: IntoZBytes
timeout?: TimeDuration,
handler?: ((sample: Reply) => Promise<void>) | Handler,
}

/**
Expand Down Expand Up @@ -302,11 +303,10 @@ export class Session {
*
* @returns Receiver
*/
async get(
get(
into_selector: IntoSelector,
handler: ((sample: Reply) => Promise<void>) | Handler = new FifoChannel(256),
get_options?: GetOptions
): Promise<Receiver | undefined> {
): Receiver | undefined {

let selector: Selector;
let key_expr: KeyExpr;
Expand All @@ -327,10 +327,17 @@ export class Session {
selector = new Selector(into_selector);
}

let handler;
if (get_options?.handler !== undefined) {
handler = get_options?.handler;
} else {
handler = new FifoChannel(256);
}

let [callback, handler_type] = this.check_handler_or_callback<Reply>(handler);

// Optional Parameters

let _consolidation = consolidation_mode_to_int(get_options?.consolidation)
let _encoding = get_options?.encoding?.toString();
let _congestion_control = congestion_control_to_int(get_options?.congestion_control);
Expand All @@ -350,7 +357,7 @@ export class Session {
_payload = Array.from(new ZBytes(get_options?.payload).buffer())
}

let chan: SimpleChannel<ReplyWS> = await this.remote_session.get(
let chan: SimpleChannel<ReplyWS> = this.remote_session.get(
selector.key_expr().toString(),
selector.parameters().toString(),
handler_type,
Expand Down Expand Up @@ -398,10 +405,10 @@ export class Session {
* @returns Subscriber
*/
// Handler size : This is to match the API_DATA_RECEPTION_CHANNEL_SIZE of zenoh internally
async declare_subscriber(
declare_subscriber(
key_expr: IntoKeyExpr,
handler: ((sample: Sample) => Promise<void>) | Handler = new FifoChannel(256),
): Promise<Subscriber> {
): Subscriber {
let _key_expr = new KeyExpr(key_expr);
let remote_subscriber: RemoteSubscriber;
let callback_subscriber = false;
Expand All @@ -415,18 +422,18 @@ export class Session {
callback(sample);
}
};
remote_subscriber = await this.remote_session.declare_remote_subscriber(
remote_subscriber = this.remote_session.declare_remote_subscriber(
_key_expr.toString(),
handler_type,
callback_conversion,
);
} else {
remote_subscriber = await this.remote_session.declare_remote_subscriber(
remote_subscriber = this.remote_session.declare_remote_subscriber(
_key_expr.toString(),
handler_type,
);
}

let subscriber = Subscriber[NewSubscriber](
remote_subscriber,
callback_subscriber,
Expand All @@ -435,7 +442,7 @@ export class Session {
return subscriber;
}

liveliness() : Liveliness {
liveliness(): Liveliness {
return new Liveliness(this.remote_session)
}

Expand All @@ -450,10 +457,10 @@ export class Session {
*
* @returns Queryable
*/
async declare_queryable(
declare_queryable(
key_expr: IntoKeyExpr,
queryable_opts?: QueryableOptions
): Promise<Queryable> {
): Queryable {
let _key_expr = new KeyExpr(key_expr);
let remote_queryable: RemoteQueryable;
let reply_tx: SimpleChannel<QueryReplyWS> =
Expand Down

0 comments on commit 0e79698

Please sign in to comment.