Skip to content

Conversation

@ClemensLey
Copy link
Contributor

@ClemensLey ClemensLey commented Jan 12, 2025

This PR adds real time support to the Bitcoin Computer. It adds a new function subscribe to the Computer class that provides real time updates.

async subscribe(id: string, onMessage: (rev: string) => void, onError?: (error: Event) => void)

Specifically, the function takes two arguments, and object id and a callback function that is called every time a function is called on the object. For example:

const a = await computer.new(C)
close = await computer.subscribe(a._id, (rev) => {
  console.log(`Update to object with id ${a._id}: the latest revision is ${rev}`)
})
await a.inc(1)
await a.inc(1)

// logs "updated on object with id ..." twice

Behind the scenes we use server side events (SSEs) which is a minimal high performance technology for server side pushs.

@ClemensLey ClemensLey changed the title Sse Real time support Jan 16, 2025
@ltardivo ltardivo merged commit c83dc0b into main Jan 17, 2025
@ltardivo ltardivo deleted the sse branch January 17, 2025 16:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants