mutex = new ThreadedMutex; $this->storage = new Internal\ParcelStorage($value); } /** * {@inheritdoc} */ public function unwrap(): Promise { return new Success($this->storage->get()); } /** * @return \Amp\Promise */ public function synchronized(callable $callback): Promise { return call(function () use ($callback) { /** @var \Amp\Sync\Lock $lock */ $lock = yield $this->mutex->acquire(); try { $result = yield call($callback, $this->storage->get()); if ($result !== null) { $this->storage->set($result); } } finally { $lock->release(); } return $result; }); } }