Skip to content
Discussion options

You must be logged in to vote

As you noticed already, classes cannot contain async initializers, but there is a synchronous API on remote function queries that should (in theory) work for your use-case:

class Printers {
	printers = $derived(getAllPrinters())

	checkOnline() {
		if (!this.printers.ready) return // ensures .current is not undefined

		for (const printer of this.printers.current) {
			console.log(printer.status)
		}
	}
}

There are synchronous values for:

  • .current (which holds the current value of the query)
  • .ready (for initial load and with type narrowing to ensure .current is not undefined)
  • .loading (also true if currently refreshing and .current still holding the stale previous value)
  • .error to get th…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@paulhahayes
Comment options

Answer selected by paulhahayes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants