feat: implement async processing for data pipeline operations
Refactor the core data processing module to use asyncio for concurrent task execution, replacing the previous synchronous loop. This change introduces async/await patterns across the main handler and utility functions, enabling non-blocking I/O for database queries and external API calls. The update includes new async context managers for connection pooling and error handling, improving throughput under high load scenarios.
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
int main() {
|
||||
printf("=== Async I/O Tests ===\n");
|
||||
|
||||
printf("Test 1: Async file write\n");
|
||||
int f = fopen("async_test.txt", "w");
|
||||
if (f == 0) {
|
||||
printf("ERROR: Could not open file\n");
|
||||
return 1;
|
||||
}
|
||||
int write_handle = async_fwrite(f, "Hello from async I/O!", 21);
|
||||
printf("Write started, handle: %d\n", write_handle);
|
||||
int result = async_wait(write_handle);
|
||||
printf("Write completed, bytes written: %d\n", result);
|
||||
fclose(f);
|
||||
printf("PASS: Async write works\n");
|
||||
|
||||
printf("Test 2: Async file read\n");
|
||||
f = fopen("async_test.txt", "r");
|
||||
if (f == 0) {
|
||||
printf("ERROR: Could not open file\n");
|
||||
return 1;
|
||||
}
|
||||
int buffer[256];
|
||||
int read_handle = async_fread(f, &buffer, 256);
|
||||
printf("Read started, handle: %d\n", read_handle);
|
||||
|
||||
printf("Polling for completion...\n");
|
||||
while (async_poll(read_handle) == 0) {
|
||||
printf(".");
|
||||
}
|
||||
printf("\nRead complete!\n");
|
||||
|
||||
result = async_result(read_handle);
|
||||
printf("Bytes read: %d\n", result);
|
||||
fclose(f);
|
||||
printf("PASS: Async read works\n");
|
||||
|
||||
printf("Test 3: Cleanup\n");
|
||||
fremove("async_test.txt");
|
||||
printf("PASS: File removed\n");
|
||||
|
||||
printf("\n=== All Async I/O Tests Completed ===\n");
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user