xiaohongshu
xiaohongshu
async-await-checker
Automatically applies when writing Python functions that call async operations. Ensures proper async/await pattern usage (not asyncio.run) to prevent event loop errors.
Full skill instructions
When you are writing or modifying Python functions that:
async defAlways apply these patterns:
# Helper function
async def fetch_user_data(user_id: str) -> dict:
"""Fetch user data from database."""
result = await db.query(user_id) # ✅ Use await
return result
# API endpoint (FastAPI)
@app.get("/users/{user_id}")
async def get_user(user_id: str) -> dict: # ✅ async def
data = await fetch_user_data(user_id) # ✅ await
return data
# Multiple async calls
async def process_order(order_id: str) -> dict:
# ✅ Run sequentially
user = await fetch_user(order_id)
payment = await process_payment(user.id)
# ✅ Run in parallel with asyncio.gather
results = await asyncio.gather(
send_email(user.email),
update_inventory(order_id),
log_transaction(payment.id)
)
return {"status": "success"}
# ❌ Don't do this
def fetch_user_data(user_id: str):
result = asyncio.run(db.query(user_id)) # ❌ asyncio.run in event loop = error!
return result
# ❌ Missing async
@app.get("/users/{user_id}")
def get_user(user_id: str): # ❌ Should be async def
data = fetch_user_data(user_id) # ❌ Not awaiting
return data
# ❌ Blocking in async function
async def process_order(order_id: str):
time.sleep(5) # ❌ Blocks event loop! Use asyncio.sleep(5)
return await fetch_data()
Runtime Error: asyncio.run() fails when called from within an already-running event loop.
Solution: Always use async def + await pattern.
Performance: Blocking operations in async functions defeat the purpose of async code.
Database queries:
async def get_records():
async with db.session() as session:
result = await session.execute(query)
return result.fetchall()
HTTP requests:
import httpx
async def fetch_api_data(url: str):
async with httpx.AsyncClient() as client:
response = await client.get(url)
return response.json()
File I/O:
import aiofiles
async def read_file(path: str):
async with aiofiles.open(path, 'r') as f:
content = await f.read()
return content
async def safe_api_call(url: str):
try:
async with httpx.AsyncClient() as client:
response = await client.get(url, timeout=10.0)
response.raise_for_status()
return response.json()
except httpx.TimeoutException:
raise TimeoutError(f"Request to {url} timed out")
except httpx.HTTPStatusError as e:
raise APIError(f"API error: {e.response.status_code}")
import pytest
@pytest.mark.asyncio
async def test_fetch_user_data():
"""Test async function"""
result = await fetch_user_data("user_123")
assert result["id"] == "user_123"
@pytest.mark.asyncio
async def test_with_mock():
"""Test with mocked async dependency"""
with patch('module.db.query') as mock_query:
mock_query.return_value = {"id": "test"}
result = await fetch_user_data("test")
assert result["id"] == "test"
# ❌ Mixing sync and async incorrectly
def sync_function():
return asyncio.run(async_function()) # Only OK at top level!
# ❌ Not using asyncio.gather for parallel operations
async def slow_version():
result1 = await operation1() # Waits
result2 = await operation2() # Waits
result3 = await operation3() # Waits
return [result1, result2, result3]
# ✅ Better: parallel execution
async def fast_version():
results = await asyncio.gather(
operation1(),
operation2(),
operation3()
)
return results
# ❌ Forgetting error handling in gather
async def unsafe():
await asyncio.gather(op1(), op2()) # If op1 fails, op2 continues
# ✅ Better: return exceptions
async def safe():
results = await asyncio.gather(
op1(), op2(),
return_exceptions=True
)
for result in results:
if isinstance(result, Exception):
handle_error(result)
async def for any function that awaitsawait for all async callsasyncio.gather() for parallel operationsasync with for async context managersasyncio.sleep() instead of time.sleep()@pytest.mark.asyncio for async testsreturn_exceptions=True in gather when appropriateWhen you see code calling async functions, automatically:
async defawait for async calls@pytest.mark.asyncio to testsxiaohongshu
technical spec
product ux expert
database patterns
Conduct multi-agent task orchestration and workflow coordination.
Initialize project with Conductor artifacts (product definition,
Expert in web animations, transitions, and motion design using Framer Motion and CSS
Creates Mermaid and ASCII diagrams for flowcharts, architecture, ERDs, state machines, mindmaps, and more. Use when user mentions diagram, flowchart, mermaid, ASCII diagram, text diagram, terminal diagram, visualize, C4, mindmap, architecture diagram, sequence diagram, ERD, or needs visual docume...
PostgreSQL bindings for H3 hexagonal grid system. Use when working with H3 cells in Postgres, including spatial indexing, geometry/geography integration, and raster analysis.
Context-Driven Development skill for projects using Conductor. Use this skill when you detect a `conductor/` directory in the project, when working on tasks defined in a `plan.md` file, or when the user asks about tracks, specs, or plans. Automatically applies TDD workflow, tracks task completion...
Display project status, active tracks, and next actions
Official Stakpak application containerization standard operating procedure, a step-by-step guidline to properly dockerize applications. This is a rule book curated by the Stakpak Team.
Generate, edit, and beat-sync AI video with leading models in one workspace.
The world's fastest calendar for remote work
Transform Your Design with AI Designer by ImgCreator.ai
Revolutionizing Video Production with AI-Powered Creativity
Extend an image past the frame and let AI fill the new aspect ratio.
Discover your celebrity doppelgänger with StarByFace!
ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.
Opus.ai: Revolutionize Your Web Experience