mirror of
https://github.com/pockethost/pockethost.git
synced 2025-03-30 15:08:30 +00:00
chore: update trySubscribe to async
This commit is contained in:
parent
b7413091aa
commit
a3a60517de
@ -164,20 +164,23 @@ const tryUserSubscribe = (() => {
|
|||||||
let unsub: UnsubscribeFunc | undefined
|
let unsub: UnsubscribeFunc | undefined
|
||||||
let tid: NodeJS.Timeout | undefined
|
let tid: NodeJS.Timeout | undefined
|
||||||
|
|
||||||
const _trySubscribe = (id?: string) => {
|
const _trySubscribe = async (id?: string) => {
|
||||||
clearTimeout(tid)
|
clearTimeout(tid)
|
||||||
unsub?.()
|
await unsub?.()
|
||||||
unsub = undefined
|
|
||||||
if (!id) return
|
if (!id) return
|
||||||
console.log('Subscribing to user', id)
|
console.log('Subscribing to user', id)
|
||||||
client()
|
client()
|
||||||
.client.collection('users')
|
.client.collection('users')
|
||||||
.subscribe<UserFields>(id, (data) => {
|
.subscribe<UserFields>(id, (data) => {
|
||||||
console.log('User subscribed update', data)
|
console.log('User subscribed update', data)
|
||||||
userStore.set(data.record)
|
client().client.collection('users').authRefresh().catch(console.error)
|
||||||
})
|
})
|
||||||
.then((u) => {
|
.then((u) => {
|
||||||
unsub = u
|
unsub = async () => {
|
||||||
|
console.log('Unsubscribing from user', id)
|
||||||
|
await u()
|
||||||
|
unsub = undefined
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
console.error('Failed to subscribe to user')
|
console.error('Failed to subscribe to user')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user