fix(backend): add async lock to prevent Already borrowed issue
This commit is contained in:
@@ -7,14 +7,18 @@ from convex import ConvexClient as SyncConvexClient
|
|||||||
class ConvexClient:
|
class ConvexClient:
|
||||||
def __init__(self, url: str) -> None:
|
def __init__(self, url: str) -> None:
|
||||||
self._client = SyncConvexClient(url)
|
self._client = SyncConvexClient(url)
|
||||||
|
self._lock = asyncio.Lock()
|
||||||
|
|
||||||
async def query(self, name: str, args: dict[str, Any] | None = None) -> Any: # noqa: ANN401
|
async def query(self, name: str, args: dict[str, Any] | None = None) -> Any: # noqa: ANN401
|
||||||
|
async with self._lock:
|
||||||
return await asyncio.to_thread(self._client.query, name, args or {})
|
return await asyncio.to_thread(self._client.query, name, args or {})
|
||||||
|
|
||||||
async def mutation(self, name: str, args: dict[str, Any] | None = None) -> Any: # noqa: ANN401
|
async def mutation(self, name: str, args: dict[str, Any] | None = None) -> Any: # noqa: ANN401
|
||||||
|
async with self._lock:
|
||||||
return await asyncio.to_thread(self._client.mutation, name, args or {})
|
return await asyncio.to_thread(self._client.mutation, name, args or {})
|
||||||
|
|
||||||
async def action(self, name: str, args: dict[str, Any] | None = None) -> Any: # noqa: ANN401
|
async def action(self, name: str, args: dict[str, Any] | None = None) -> Any: # noqa: ANN401
|
||||||
|
async with self._lock:
|
||||||
return await asyncio.to_thread(self._client.action, name, args or {})
|
return await asyncio.to_thread(self._client.action, name, args or {})
|
||||||
|
|
||||||
def subscribe(self, name: str, args: dict[str, Any] | None = None) -> Any: # noqa: ANN401
|
def subscribe(self, name: str, args: dict[str, Any] | None = None) -> Any: # noqa: ANN401
|
||||||
|
|||||||
@@ -2,13 +2,15 @@
|
|||||||
import './layout.css';
|
import './layout.css';
|
||||||
import favicon from '$lib/assets/favicon.svg';
|
import favicon from '$lib/assets/favicon.svg';
|
||||||
import { PUBLIC_CONVEX_URL } from '$env/static/public';
|
import { PUBLIC_CONVEX_URL } from '$env/static/public';
|
||||||
|
import { env } from '$env/dynamic/public';
|
||||||
import { setupConvex } from 'convex-svelte';
|
import { setupConvex } from 'convex-svelte';
|
||||||
import { hasWebSocketSupport, setupPollingConvex } from '$lib/convex-polling.svelte';
|
import { hasWebSocketSupport, setupPollingConvex } from '$lib/convex-polling.svelte';
|
||||||
import { setContext } from 'svelte';
|
import { setContext } from 'svelte';
|
||||||
|
|
||||||
let { children } = $props();
|
let { children } = $props();
|
||||||
|
|
||||||
const usePolling = !hasWebSocketSupport();
|
const fallbackEnabled = env.PUBLIC_FALLBACK === '1';
|
||||||
|
const usePolling = fallbackEnabled && !hasWebSocketSupport();
|
||||||
setContext('convex-use-polling', usePolling);
|
setContext('convex-use-polling', usePolling);
|
||||||
|
|
||||||
if (usePolling) {
|
if (usePolling) {
|
||||||
|
|||||||
Reference in New Issue
Block a user