Skip to content

Commit bebc86f

Browse files
committed
wait for send to complete
1 parent e3882c9 commit bebc86f

3 files changed

Lines changed: 50 additions & 1 deletion

File tree

public/example.html

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,19 @@
1010

1111
<script>
1212

13+
function makeid(length) {
14+
let result = '';
15+
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
16+
const charactersLength = characters.length;
17+
let counter = 0;
18+
while (counter < length) {
19+
result += characters.charAt(Math.floor(Math.random() * charactersLength));
20+
counter += 1;
21+
}
22+
return result;
23+
}
24+
25+
1326
async function init(){
1427

1528
config = new Dataparty.Config.MemoryConfig({
@@ -58,6 +71,36 @@
5871
console.log(name, msg)
5972
})
6073

74+
75+
let text = makeid(500*1024)
76+
77+
let first = true
78+
79+
async function onTimeout(){
80+
81+
let num = first ? 2:1
82+
83+
first = false
84+
85+
let statusId = 'publish:'+timeTopic.name+':'+ (party.comms.ros.idCounter+num)
86+
87+
console.log(statusId)
88+
89+
90+
party.comms.once(statusId,(status)=>{
91+
console.log('status', status)
92+
93+
setTimeout(onTimeout, 0)
94+
})
95+
96+
await timeTopic.publish({number: Date.now(), text:text})
97+
98+
99+
}
100+
101+
window.onTimeout = onTimeout
102+
103+
//onTimeout()
61104
}
62105

63106
init()

src/comms/peer-comms.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ class PeerComms extends SocketComms {
128128
...op.result
129129
}
130130

131-
debug(response.id, response.state, response.stats.duration_ms, 'ms')
131+
debug('finished', response.id, response.state, response.stats.duration_ms, 'ms')
132132

133133
this.send(response)
134134
})

src/comms/ros-shim.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ class RosShim extends ROSLIB.Ros {
2626

2727

2828
handleMessage(message) {
29+
30+
console.log(message)
31+
2932
if (message.op === 'publish') {
3033
debug('publish op')
3134
this.emit(message.topic, message.msg);
@@ -34,6 +37,9 @@ class RosShim extends ROSLIB.Ros {
3437
} else if (message.op === 'call_service') {
3538
this.emit(message.service, message);
3639
}*/ else if(message.op === 'status'){
40+
41+
console.log('status', message)
42+
3743
if(message.id){
3844
this.emit('status:'+message.id, message);
3945
} else {

0 commit comments

Comments
 (0)