Skip to content

Commit

Permalink
fix exponential retries
Browse files Browse the repository at this point in the history
  • Loading branch information
zippy committed Aug 28, 2024
1 parent 2254a33 commit 8b15ea4
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 23 deletions.
2 changes: 1 addition & 1 deletion ui/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ui",
"version": "0.0.1",
"version": "0.0.2",
"dnaVersion": "0.0.1",
"scripts": {
"start": "vite --clearScreen false --port $UI_PORT",
Expand Down
12 changes: 6 additions & 6 deletions ui/src/StreamPane.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -76,18 +76,18 @@
let count = parseInt(inputCountElement.value)
let delay = parseInt(inputDelayElement.value)
setTimeout(() => {
_sendMessage()
_sendMessage(inputCountElement.value)
count-=1
inputCountElement.value = `${count}`
if (count>0) {
sendMessage()
}
}, delay);
}
const _sendMessage = async () => {
const _sendMessage = async (text) => {
const payload: Payload = {
type: "Msg",
text: inputElement.value,
text,
created: Date.now(),
}
console.log("SENDING TO",hashes)
Expand Down Expand Up @@ -267,16 +267,16 @@
label="Delay"
></sl-input>
<sl-input
style="width:100%"
style="width:300px"
bind:this={inputElement}
on:sl-input={(e) => (disabled = !e.target.value || !inputElement.value)}
on:keydown={(e) => {
if (e.keyCode == 13) {
sendMessage();
_sendMessage(inputElement.value);
e.stopPropagation();
}
}}
placeholder="Message"
label="Message"
></sl-input>

<sl-button
Expand Down
32 changes: 16 additions & 16 deletions ui/src/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export class ZipTestClient extends ZomeClient<ZipTestSignal> {
}

async sendMessage(streamId: string, payload: Payload, agents: AgentPubKey[]) {
console.log("Sending", payload, "to", agents.map(agent=>encodeHashToBase64(agent)))
await this.callZome('send_message', {
streamId,
content: JSON.stringify(payload),
Expand Down Expand Up @@ -122,7 +123,6 @@ export class ZipTestStore {
});

async sendMessage(streamId: string, payload: Payload, agents: AgentPubKey[]) {
console.log("Sending Message to", agents.map(agent=>encodeHashToBase64(agent)))
this.addMessageToStream(streamId, {payload, from:this.myAgentPubKey, received:Date.now() })
for (const agent of agents) {
let messageList:Array<number> = this.expectations.get(agent)
Expand Down Expand Up @@ -165,10 +165,10 @@ export class ZipTestStore {
stream = this.newStream(streamId)
}

stream.addMessage(message)
const firstAdd = stream.addMessage(message)
if (message.payload.type == "Msg") {
if (isWeContext()) {
this.weaveClient.notifyFrame([
if (firstAdd && isWeContext()) {
await this.weaveClient.notifyFrame([
{
title: `message from ${encodeHashToBase64(message.from)}`,
body: message.payload.text,
Expand Down Expand Up @@ -225,18 +225,18 @@ export class ZipTestStore {
}
// we just received a message from someone who we are expecting
// to have acked something but they haven't so we retry to send the message
if (messageList.length > 0) {
const streams = Object.values(get(this.streams))
for (const msgId of messageList) {
for (const stream of streams) {
const msg = stream.findMessage(msgId)
if (msg) {
console.log("Resending", msg)
await this.client.sendMessage(stream.id, msg.payload, [message.from])
}
}
}
}
// if (messageList.length > 0) {
// const streams = Object.values(get(this.streams))
// for (const msgId of messageList) {
// for (const stream of streams) {
// const msg = stream.findMessage(msgId)
// if (msg) {
// console.log("Resending", msg)
// await this.client.sendMessage(stream.id, msg.payload, [message.from])
// }
// }
// }
// }
}
}

Expand Down

0 comments on commit 8b15ea4

Please sign in to comment.