MultiLock constructor

MultiLock({
  1. required Iterable<Lock> locks,
})

Creates a lock that acquires every lock in locks together.

locks is copied, so the lock set is fixed at construction: iterating it later must not be able to yield a different result. Passing a lazy Iterable that rebuilds its elements on each iteration would otherwise mean acquiring a different lock every time, silently providing no mutual exclusion at all.

The captured list is walked in order on each synchronized call to acquire (and, in reverse, to release) each underlying lock.

Implementation

MultiLock({required Iterable<Lock> locks}) : _locks = List<Lock>.of(locks);