Todo list and multiple Workers

Let say i have 3 ymap : todo, doing, done.
We can have multiple workers that observe todo map , and when something new in todo, each worker can do .

let task = todo.get(first_id)
task.worker=me
task.state=“doing”
todo.delete (first_id)
doing.set(first_id, task)

How to be sure that only one worker take the task with a remote y-websocket server ?

I’ve tried to change the state of task as soon as possible , but all workers take the task as soon at it is available, and before one delete it from todo
And all worker work on the task whereas i would like only one worker. But i’m not able to lock/mark a task as already taken before the other take it too.
I want only one worker work on it and other worker take other task in todo map

I think you need a central node to hand out the tasks to the workers. The workers ask for a task, and the central node can give it to just one.

In the fully decentralized situation, there is always a point in time where every worker sees that there is an available task and every worker thinks it is safe to take it, without realizing that other workers are doing the same.

I’m not an expert in peer-to-peer networking though so maybe there is a solution I’m not aware of.

1 Like