# Poll for Completion

## Content: Poll for Completion

### User Intent

"I want to know when content processing has finished"

### Operation

* **SDK Method**: `graphlit.isContentDone()`
* **GraphQL**: `isContentDone` query
* **Entity Type**: Content
* **Common Use Cases**: Wait for async ingestion, check processing status

### TypeScript (Canonical)

```typescript
import { Graphlit } from 'graphlit-client';
import { Types } from 'graphlit-client/dist/generated/graphql-types';

const graphlit = new Graphlit();

// After async ingestion
const contentResponse = await graphlit.ingestUri(
  'https://example.com/document.pdf',
  undefined, undefined, undefined,
  false  // isSynchronous = false (async)
);

const contentId = contentResponse.ingestUri.id;

console.log('Content ingestion started, polling for completion...');

// Poll for completion
let isDone = false;
let attempts = 0;
const maxAttempts = 60;  // 10 minutes max

while (!isDone && attempts < maxAttempts) {
  const status = await graphlit.isContentDone(contentId);
  isDone = status.isContentDone.result || false;
  
  if (!isDone) {
    attempts++;
    console.log(`Still processing... (${attempts}/${maxAttempts})`);
    await new Promise(resolve => setTimeout(resolve, 10000));  // Wait 10 seconds
  }
}

if (isDone) {
  console.log(' Content processing complete!');
  
  // Now safe to access content
  const content = await graphlit.getContent(contentId);
  console.log(`Extracted ${content.content.markdown?.length || 0} chars`);
} else {
  console.log('⏰ Timeout - still processing');
}
```

## After async ingestion

content\_response = await graphlit.ingestUri( uri="<https://example.com/document.pdf>", is\_synchronous=False )

content\_id = content\_response.ingest\_uri.id

## Poll for completion (snake\_case)

is\_done = False attempts = 0 max\_attempts = 60

while not is\_done and attempts < max\_attempts: status = await graphlit.isContentDone(content\_id) is\_done = status.is\_content\_done.result if status.is\_content\_done else False

```
if not is_done:
    attempts += 1
    print(f"Still processing... ({attempts}/{max_attempts})")
    await asyncio.sleep(10)
```

if is\_done: print(" Content processing complete!")

````

**C#**:
```csharp
using Graphlit;
using System.Threading.Tasks;

var client = new Graphlit();

// After async ingestion
var contentResponse = await graphlit.IngestUri(
    uri: "https://example.com/document.pdf",
    isSynchronous: false
);

var contentId = contentResponse.IngestUri.Id;

// Poll for completion (PascalCase)
bool isDone = false;
int attempts = 0;
int maxAttempts = 60;

while (!isDone && attempts < maxAttempts)
{
    var status = await graphlit.IsContentDone(contentId);
    isDone = status.IsContentDone?.Result ?? false;
    
    if (!isDone)
    {
        attempts++;
        Console.WriteLine($"Still processing... ({attempts}/{maxAttempts})");
        await Task.Delay(10000);  // Wait 10 seconds
    }
}

if (isDone)
{
    Console.WriteLine(" Content processing complete!");
}
````

### Parameters

* **`id`** (string): Content ID to check

### Response

```typescript
{
  isContentDone: {
    result: boolean;  // true = complete, false = still processing
  }
}
```

### Developer Hints

#### Async vs Sync Ingestion

```typescript
// Synchronous - waits automatically
const content = await graphlit.ingestUri(uri, undefined, undefined, undefined, true);
// Content ready immediately

// Asynchronous - need to poll
const content = await graphlit.ingestUri(uri, undefined, undefined, undefined, false);
// Poll with isContentDone()
```

#### Polling Helper Function

```typescript
async function waitForContent(
  contentId: string,
  timeoutMinutes: number = 10
): Promise<boolean> {
  const maxAttempts = timeoutMinutes * 6;  // 6 checks per minute
  let attempts = 0;
  
  while (attempts < maxAttempts) {
    const status = await graphlit.isContentDone(contentId);
    
    if (status.isContentDone.result) {
      return true;
    }
    
    attempts++;
    await new Promise(resolve => setTimeout(resolve, 10000));
  }
  
  return false;  // Timeout
}

// Usage
const done = await waitForContent(contentId, 10);
if (done) {
  console.log('Ready!');
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.graphlit.dev/api-guides/use-cases/content/content-is-done-polling.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
