What is an idempotent operation?

前端 未结 15 1157
情话喂你
情话喂你 2020-11-22 03:27

What is an idempotent operation?

15条回答
  •  我寻月下人不归
    2020-11-22 03:53

    A good example of understanding an idempotent operation might be locking a car with remote key.

    log(Car.state) // unlocked
    
    Remote.lock();
    log(Car.state) // locked
    
    Remote.lock();
    Remote.lock();
    Remote.lock();
    log(Car.state) // locked
    

    lock is an idempotent operation. Even if there are some side effect each time you run lock, like blinking, the car is still in the same locked state, no matter how many times you run lock operation.

提交回复
热议问题