Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
legokichi committed Jul 4, 2023
1 parent 2a8fbc6 commit 5c469ca
Show file tree
Hide file tree
Showing 18 changed files with 1,269 additions and 0 deletions.
12 changes: 12 additions & 0 deletions blocking/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[package]
name = "blocking"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
blocking = "1.3"
tokio = { version = "1", features = ["full"] }
futures = "0.3"

39 changes: 39 additions & 0 deletions blocking/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@

#[tokio::main]
async fn main() {
let fut = blocking::unblock(||{
loop{
println!("a");
std::thread::sleep(std::time::Duration::from_secs(1));
}
});
let fut2 = tokio::task::spawn_blocking(||{
loop{
println!("b");
std::thread::sleep(std::time::Duration::from_secs(1));
}
});
let fut3 = async {
loop {
println!("c");
tokio::time::sleep(std::time::Duration::from_secs(1)).await;
}
};
let fut4 = tokio::time::sleep(std::time::Duration::from_secs(3));
tokio::select!{
_ = fut => {
println!("never");
}
_ = fut2 => {
println!("never");
}
_ = fut3 => {
println!("never");
}
_ = fut4 => {
println!("done");
}
}
tokio::time::sleep(std::time::Duration::from_secs(3)).await;
println!("fin");
}
22 changes: 22 additions & 0 deletions mqtt-pah/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[package]
name = "mqtt-pah"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[features]
default = ["paho"]
paho = ["paho-mqtt", "paho-mqtt-sys", "tempfile"]
rumqtt = ["rumqttc", "rustls-pemfile"]

[dependencies]
anyhow = "1"
futures = "0.3"
log = "0.4"
paho-mqtt = { version = "0.12", features = ["bundled", "build_bindgen"], optional = true }
paho-mqtt-sys = { version = "0.8", optional = true }
rumqttc = { version = "0.22", optional = true }
rustls-pemfile = { version = "1.0", optional = true }
tempfile = { version = "3.6.0", optional = true }
tokio = { version = "1", features = ["full"] }
env_logger = "0.10"
70 changes: 70 additions & 0 deletions mqtt-pah/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
const mqtt = require('mqtt')
const aedes = require('aedes')()
const server = require('net').createServer(aedes.handle)
const port = 1883

const evs = [
"client",
"clientReady",
"clientDisconnect",
"clientError",
"connectionError",
"keepaliveTimeout",
"publish",
"ack",
"ping",
"subscribe",
"unsubscribe",
"connackSent",
"closed",
//
"error",
"ready",
"new",
];
for(const ev of evs){
aedes.on(ev, (...args)=>{
args.pop();
console.info.bind(console, "aedes", ev, ...args)
});
}
aedes.on("client", (client)=>{
console.info("aedes","client");
const evs = [
"connected",
"error",
];
for(const ev of evs){
client.on(ev, console.info.bind(console, "aedes client", ev));
}
});

server.listen(port, function () {
console.log('server started and listening on port ', port)
//const mclient = mqtt.connect(`mqtt://127.0.0.1:${port}`);
//const evs = [
// "connect",
// "reconnect",
// "close",
// "disconnect",
// "offline",
// "error",
// "end",
// "message",
// "packetsend",
// "packetreceive",
//];
//for(ev of evs){
// mclient.on(ev, console.info.bind(console, "mqtt", ev));
//}

aedes.on("clientReady", (client)=>{
console.log("aedes clientReady");
setTimeout(()=>{
console.log("aedes client closing");
client.close(()=>{
console.log("aedes client closed");
});
}, 6000);
});
});
Loading

0 comments on commit 5c469ca

Please sign in to comment.