Skip to content

Commit

Permalink
Add Subscriber Options, include handler / callback option
Browse files Browse the repository at this point in the history
  • Loading branch information
Charles-Schleich committed Dec 16, 2024
1 parent 0e79698 commit 30007ab
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion zenoh-ts/src/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ export interface DeleteOptions {
* @prop {Encoding=} encoding - Encoding type of payload
* @prop {IntoZBytes=} payload - Payload associated with getrequest
* @prop {IntoZBytes=} attachment - Additional Data sent with the request
* @prop {TimeDuration=} timeout - Timeout value for a get request
* @prop {((sample: Reply) => Promise<void>) | Handler} handler - either a callback or a polling handler with an underlying handling mechanism
*/
export interface GetOptions {
consolidation?: ConsolidationMode,
Expand All @@ -114,6 +116,13 @@ export interface GetOptions {
handler?: ((sample: Reply) => Promise<void>) | Handler,
}

/**
* Options for a SubscriberOpts function
*/
export interface SubscriberOpts {
handler?: ((sample: Sample) => Promise<void>) | Handler,
}

/**
* Options for a Queryable
* @prop complete - Change queryable completeness.
Expand Down Expand Up @@ -407,11 +416,19 @@ export class Session {
// Handler size : This is to match the API_DATA_RECEPTION_CHANNEL_SIZE of zenoh internally
declare_subscriber(
key_expr: IntoKeyExpr,
handler: ((sample: Sample) => Promise<void>) | Handler = new FifoChannel(256),
subscriber_opts: SubscriberOpts
): Subscriber {
let _key_expr = new KeyExpr(key_expr);
let remote_subscriber: RemoteSubscriber;

let callback_subscriber = false;
// let [callback, handler_type] = this.check_handler_or_callback<Sample>(handler);
let handler;
if (subscriber_opts?.handler !== undefined) {
handler = subscriber_opts?.handler;
} else {
handler = new FifoChannel(256);
}
let [callback, handler_type] = this.check_handler_or_callback<Sample>(handler);

if (callback !== undefined) {
Expand Down

0 comments on commit 30007ab

Please sign in to comment.