( taskListId: string, taskData: Omit<Task, 'id'>, )
| 282 | * create tasks concurrently. |
| 283 | */ |
| 284 | export async function createTask( |
| 285 | taskListId: string, |
| 286 | taskData: Omit<Task, 'id'>, |
| 287 | ): Promise<string> { |
| 288 | const lockPath = await ensureTaskListLockFile(taskListId) |
| 289 | |
| 290 | let release: (() => Promise<void>) | undefined |
| 291 | try { |
| 292 | // Acquire exclusive lock on the task list |
| 293 | release = await lockfile.lock(lockPath, LOCK_OPTIONS) |
| 294 | |
| 295 | // Read highest ID from disk while holding the lock |
| 296 | const highestId = await findHighestTaskId(taskListId) |
| 297 | const id = String(highestId + 1) |
| 298 | const task: Task = { id, ...taskData } |
| 299 | const path = getTaskPath(taskListId, id) |
| 300 | await writeFile(path, jsonStringify(task, null, 2)) |
| 301 | notifyTasksUpdated() |
| 302 | return id |
| 303 | } finally { |
| 304 | if (release) { |
| 305 | await release() |
| 306 | } |
| 307 | } |
| 308 | } |
| 309 | |
| 310 | export async function getTask( |
| 311 | taskListId: string, |
no test coverage detected