Skip to content

Commit

Permalink
πŸ“ƒ WS message log for debugging (#2926)
Browse files Browse the repository at this point in the history
  • Loading branch information
fonsp authored May 24, 2024
1 parent fd05a2b commit d825774
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 16 deletions.
20 changes: 13 additions & 7 deletions frontend/common/PlutoConnection.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Promises } from "../common/SetupCellEnvironment.js"
import { pack, unpack } from "./MsgPack.js"
import "./Polyfill.js"
import { Stack } from "./Stack.js"
import { with_query_params } from "./URLTools.js"

const reconnect_after_close_delay = 500
Expand Down Expand Up @@ -249,6 +250,7 @@ const default_ws_address = () => ws_address_from_base(window.location.href)
* dismiss_update_notification: boolean,
* },
* notebook_exists: boolean,
* message_log: import("./Stack.js").Stack<any>,
* }}
*/

Expand Down Expand Up @@ -279,18 +281,21 @@ export const create_pluto_connection = async ({
ws_address = default_ws_address(),
}) => {
let ws_connection = /** @type {WebsocketConnection?} */ (null) // will be defined later i promise
const message_log = new Stack(100)
// @ts-ignore
window.pluto_get_message_log = () => message_log.get()

/** @type {PlutoConnection} */
const client = {
send: null,
session_options: null,
// send: null,
// session_options: null,
version_info: {
julia: "unknown",
pluto: "unknown",
dismiss_update_notification: false,
},
notebook_exists: true,
kill: null,
// kill: null,
message_log,
} // same

const client_id = get_unique_short_id()
Expand All @@ -303,6 +308,7 @@ export const create_pluto_connection = async ({
}
const request_id = get_unique_short_id()

// This data will be sent:
const message = {
type: message_type,
client_id: client_id,
Expand All @@ -311,8 +317,6 @@ export const create_pluto_connection = async ({
...metadata,
}

// Note: Message to be sent: message

let p = resolvable_promise()

sent_requests.set(request_id, (response_message) => {
Expand Down Expand Up @@ -350,6 +354,8 @@ export const create_pluto_connection = async ({
try {
ws_connection = await create_ws_connection(String(ws_address), {
on_message: (update) => {
message_log.push(update)

const by_me = update.initiator_id == client_id
const request_id = update.request_id

Expand Down Expand Up @@ -418,5 +424,5 @@ export const create_pluto_connection = async ({
}
await connect()

return client
return /** @type {PlutoConnection} */ (client)
}
29 changes: 29 additions & 0 deletions frontend/common/Stack.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* @template T
* @type {Stack<T>}
*/
export class Stack {
/**
* @param {number} max_size
*/
constructor(max_size) {
this.max_size = max_size
this.arr = []
}
/**
* @param {T} item
* @returns {void}
*/
push(item) {
this.arr.push(item)
if (this.arr.length > this.max_size) {
this.arr.shift()
}
}
/**
* @returns {T[]}
*/
get() {
return this.arr
}
}
12 changes: 3 additions & 9 deletions frontend/components/Editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -811,15 +811,9 @@ patch: ${JSON.stringify(
this.waiting_for_bond_to_trigger_execution = false
}
}
apply_promise
.then(set_waiting)
.catch((e) => {
set_waiting()
throw e
})
.then(() => {
this.send_queued_bond_changes()
})
apply_promise.finally(set_waiting).then(() => {
this.send_queued_bond_changes()
})

break
default:
Expand Down

0 comments on commit d825774

Please sign in to comment.