diff --git a/zenoh-ts/examples/src/z_pong.ts b/zenoh-ts/examples/src/z_pong.ts index c713fb9..2097328 100644 --- a/zenoh-ts/examples/src/z_pong.ts +++ b/zenoh-ts/examples/src/z_pong.ts @@ -26,7 +26,7 @@ export async function main() { ); const subscriber_callback = async function (sample: Sample): Promise { - await pub.put(sample.payload()); + pub.put(sample.payload()); }; await session.declare_subscriber("test/pong", subscriber_callback); diff --git a/zenoh-ts/src/remote_api/session.ts b/zenoh-ts/src/remote_api/session.ts index 7906007..f0f3c6d 100644 --- a/zenoh-ts/src/remote_api/session.ts +++ b/zenoh-ts/src/remote_api/session.ts @@ -167,7 +167,7 @@ export class RemoteSession { } // get - async get( + get( key_expr: string, parameters: string | null, handler: HandlerChannel, @@ -179,7 +179,7 @@ export class RemoteSession { payload?: Array, attachment?: Array, timeout_ms?: number, - ): Promise> { + ): SimpleChannel { let uuid = uuidv4(); let channel: SimpleChannel = new SimpleChannel(); this.get_receiver.set(uuid, channel); @@ -214,13 +214,13 @@ export class RemoteSession { } // delete - async delete( + delete( key_expr: string, congestion_control?: number, priority?: number, express?: boolean, attachment?: Array - ): Promise { + ): void { let owned_keyexpr: OwnedKeyExprWrapper = key_expr; let opt_attachment = undefined; if (attachment != undefined) { @@ -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, - ): Promise { + callback?: (sample: SampleWS) => void, + ): RemoteSubscriber { let uuid = uuidv4(); let control_message: ControlMsg = { @@ -384,7 +384,7 @@ export class RemoteSession { declare_liveliness_subscriber( key_expr: string, history: boolean, - callback?: (sample: SampleWS) => Promise, + callback?: (sample: SampleWS) => void, ): RemoteSubscriber { let uuid = uuidv4(); @@ -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") { @@ -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]; diff --git a/zenoh-ts/src/session.ts b/zenoh-ts/src/session.ts index c08668c..ab7f0b1 100644 --- a/zenoh-ts/src/session.ts +++ b/zenoh-ts/src/session.ts @@ -111,6 +111,7 @@ export interface GetOptions { payload?: IntoZBytes, attachment?: IntoZBytes timeout?: TimeDuration, + handler?: ((sample: Reply) => Promise) | Handler, } /** @@ -302,11 +303,10 @@ export class Session { * * @returns Receiver */ - async get( + get( into_selector: IntoSelector, - handler: ((sample: Reply) => Promise) | Handler = new FifoChannel(256), get_options?: GetOptions - ): Promise { + ): Receiver | undefined { let selector: Selector; let key_expr: KeyExpr; @@ -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(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); @@ -350,7 +357,7 @@ export class Session { _payload = Array.from(new ZBytes(get_options?.payload).buffer()) } - let chan: SimpleChannel = await this.remote_session.get( + let chan: SimpleChannel = this.remote_session.get( selector.key_expr().toString(), selector.parameters().toString(), handler_type, @@ -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) | Handler = new FifoChannel(256), - ): Promise { + ): Subscriber { let _key_expr = new KeyExpr(key_expr); let remote_subscriber: RemoteSubscriber; let callback_subscriber = false; @@ -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, @@ -435,7 +442,7 @@ export class Session { return subscriber; } - liveliness() : Liveliness { + liveliness(): Liveliness { return new Liveliness(this.remote_session) } @@ -450,10 +457,10 @@ export class Session { * * @returns Queryable */ - async declare_queryable( + declare_queryable( key_expr: IntoKeyExpr, queryable_opts?: QueryableOptions - ): Promise { + ): Queryable { let _key_expr = new KeyExpr(key_expr); let remote_queryable: RemoteQueryable; let reply_tx: SimpleChannel =