Back to all reviewers

Ensure proper async context

appwrite/appwrite
Based on 4 comments
Markdown

Always wrap asynchronous operations (await, suspend functions, try-await) in the appropriate language-specific async context. Top-level await is generally not supported and will cause runtime errors.

Concurrency Markdown

Reviewer Prompt

Always wrap asynchronous operations (await, suspend functions, try-await) in the appropriate language-specific async context. Top-level await is generally not supported and will cause runtime errors.

JavaScript/Node.js (CommonJS):

// ❌ Incorrect - top-level await
const result = await databases.createDocuments(...);

// ✅ Correct - async IIFE with error handling
(async () => {
  try {
    const result = await databases.createDocuments(...);
    console.log(result);
  } catch (error) {
    console.error(error);
  }
})();

Swift:

// ❌ Incorrect - try-await outside async context
let documentList = try await databases.upsertDocuments(...);

// ✅ Correct - Task with do-catch
Task {
  do {
    let documentList = try await databases.upsertDocuments(...);
    print(documentList);
  } catch {
    print("Error:", error);
  }
}

C#:

// ❌ Incorrect - await outside async method
DocumentList result = await databases.CreateDocuments(...);

// ✅ Correct - async method
public static async Task Main(string[] args)
{
    DocumentList result = await databases.CreateDocuments(...);
    Console.WriteLine(result);
}

Always include appropriate error handling for asynchronous operations to prevent unhandled promise/task rejections and improve debugging.

4
Comments Analyzed
Markdown
Primary Language
Concurrency
Category

Source Discussions