Skip to content
Discussion options

You must be logged in to vote

Reassigning onmessage is safe — Channel calls whatever's currently on onmessage at message time, no captured reference from creation. Swapping mid-stream works.

That said, for the "user leaves and comes back" case I'd keep onmessage stable and dispatch via a registry, because reassigning from a component is fragile (you can drop the new handler if a remount races the reassignment):

import { Channel } from '@tauri-apps/api/core'

class StableChannel<T> {
  channel = new Channel<T>()
  listeners = new Set<(d: T) => void>()
  constructor() {
    this.channel.onmessage = (d) => this.listeners.forEach(l => l(d))
  }
  subscribe(l: (d: T) => void) {
    this.listeners.add(l)
    return () => this.

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by Kynson
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants