SemaphoreFactory example

$keys = [];
        $store
            ->expects($this->exactly(2))
            ->method('save')
            ->with($this->callback(function D$key) use (&$keys) {
                $keys[] = $key;

                return true;
            }));

        $logger = $this->createMock(LoggerInterface::class);
        $factory = new SemaphoreFactory($store);
        $factory->setLogger($logger);

        $semaphore1 = $factory->createSemaphore('foo', 4);
        $semaphore2 = $factory->createSemaphore('foo', 4);

        // assert lock1 and lock2 don't share the same state         $semaphore1->acquire();
        $semaphore2->acquire();

        $this->assertNotSame($keys[0]$keys[1]);
    }

    
Home | Imprint | This part of the site doesn't use cookies.