MCPcopy
hub / github.com/coder/mux / waitForWorkspaceTurn

Method waitForWorkspaceTurn

src/node/services/taskService.ts:4884–5008  ·  view source on GitHub ↗
(
    handleId: string,
    options: {
      timeoutMs?: number;
      abortSignal?: AbortSignal;
      requestingWorkspaceId: string;
      backgroundOnMessageQueued?: boolean;
    }
  )

Source from the content-addressed store, hash-verified

4882 }
4883
4884 async waitForWorkspaceTurn(
4885 handleId: string,
4886 options: {
4887 timeoutMs?: number;
4888 abortSignal?: AbortSignal;
4889 requestingWorkspaceId: string;
4890 backgroundOnMessageQueued?: boolean;
4891 }
4892 ): Promise<WorkspaceTurnWaitResult> {
4893 assert(handleId.length > 0, "waitForWorkspaceTurn: handleId must be non-empty");
4894 assert(
4895 options.requestingWorkspaceId.length > 0,
4896 "waitForWorkspaceTurn: requestingWorkspaceId must be non-empty"
4897 );
4898 const timeoutMs = options.timeoutMs ?? 120_000;
4899 assert(Number.isFinite(timeoutMs) && timeoutMs > 0, "waitForWorkspaceTurn: timeoutMs invalid");
4900
4901 this.markTaskForegroundRelevant(handleId);
4902
4903 return await new Promise<WorkspaceTurnWaitResult>((resolve, reject) => {
4904 let settled = false;
4905 let timer: ReturnType<typeof setTimeout> | null = null;
4906 let abortListener: (() => void) | null = null;
4907 let stopBlockingRequester: (() => void) | null = this.startForegroundAwait(
4908 options.requestingWorkspaceId
4909 );
4910 const shouldBackgroundOnQueuedMessage = options.backgroundOnMessageQueued ?? true;
4911
4912 const cleanup = () => {
4913 if (settled) return;
4914 settled = true;
4915 if (timer) {
4916 clearTimeout(timer);
4917 timer = null;
4918 }
4919 if (abortListener) {
4920 options.abortSignal?.removeEventListener("abort", abortListener);
4921 abortListener = null;
4922 }
4923 if (waiterEntry.backgroundOnMessageQueued && waiterEntry.requestingWorkspaceId) {
4924 this.unregisterBackgroundableForegroundWaiter(
4925 waiterEntry.requestingWorkspaceId,
4926 waiterEntry
4927 );
4928 }
4929 const waiters = this.pendingWorkspaceTurnWaitersByHandleId.get(handleId) ?? [];
4930 const nextWaiters = waiters.filter((waiter) => waiter !== waiterEntry);
4931 if (nextWaiters.length === 0) {
4932 this.pendingWorkspaceTurnWaitersByHandleId.delete(handleId);
4933 } else {
4934 this.pendingWorkspaceTurnWaitersByHandleId.set(handleId, nextWaiters);
4935 }
4936 if (stopBlockingRequester) {
4937 try {
4938 stopBlockingRequester();
4939 } finally {
4940 stopBlockingRequester = null;
4941 }

Callers 3

createTaskToolFunction · 0.80
awaitOneFunction · 0.80

Calls 15

startForegroundAwaitMethod · 0.95
rejectFunction · 0.85
setMethod · 0.80
getWorkspaceTurnMethod · 0.80
resolveMethod · 0.80
cleanupFunction · 0.70
resolveFunction · 0.70
getMethod · 0.65

Tested by

no test coverage detected