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