-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9b883eb
commit bd64a24
Showing
3 changed files
with
68 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// | ||
// Copyright (c) 2024 ZettaScale Technology | ||
// | ||
// This program and the accompanying materials are made available under the | ||
// terms of the Eclipse Public License 2.0 which is available at | ||
// http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 | ||
// which is available at https://www.apache.org/licenses/LICENSE-2.0. | ||
// | ||
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 | ||
// | ||
// Contributors: | ||
// ZettaScale Zenoh Team, <[email protected]> | ||
// | ||
|
||
import { Duration, deserialize_string, ReplyError, Config, Receiver, RecvErr, Reply, Sample, Session, QueryTarget } from "@eclipse-zenoh/zenoh-ts"; | ||
|
||
|
||
export async function main() { | ||
const session = await Session.open(new Config("ws/127.0.0.1:10000")); | ||
|
||
|
||
let querier = session.declare_querier("demo/example/**", | ||
{ | ||
target: QueryTarget.BestMatching, | ||
timeout: Duration.milliseconds.of(10000), | ||
} | ||
); | ||
|
||
for(let i =0; i<1000; i++) { | ||
sleep(1000) | ||
let payload = "["+i+"] Querier Get from Zenoh-ts!"; | ||
let receiver = querier.get({payload:payload}) as Receiver; | ||
|
||
let reply = await receiver.receive(); | ||
|
||
while (reply != RecvErr.Disconnected) { | ||
if (reply == RecvErr.MalformedReply) { | ||
console.warn("MalformedReply"); | ||
} else { | ||
let resp = reply.result(); | ||
if (resp instanceof Sample) { | ||
let sample: Sample = resp; | ||
console.warn(">> Received ('", sample.keyexpr(), ":", sample.payload().deserialize(deserialize_string), "')"); | ||
} else { | ||
let reply_error: ReplyError = resp; | ||
console.warn(">> Received (ERROR: '{", reply_error.payload().deserialize(deserialize_string), "}')"); | ||
} | ||
} | ||
reply = await receiver.receive(); | ||
} | ||
console.warn("Get Finished"); | ||
|
||
} | ||
|
||
} | ||
|
||
function sleep(ms: number) { | ||
return new Promise((resolve) => setTimeout(resolve, ms)); | ||
} | ||
|
||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters