Semaphore.hx 507 B

12345678910111213141516171819202122232425
  1. package sys.thread;
  2. import python.lib.threading.Semaphore as NativeSemaphore;
  3. @:noDoc
  4. @:coreApi
  5. class Semaphore {
  6. final semaphore:NativeSemaphore;
  7. public function new(value:Int):Void {
  8. this.semaphore = new NativeSemaphore(value);
  9. }
  10. public function acquire():Void {
  11. semaphore.acquire();
  12. }
  13. public function tryAcquire(?timeout:Float):Bool {
  14. return timeout == null ? semaphore.acquire(false) : semaphore.acquire(true, timeout);
  15. }
  16. public function release():Void {
  17. semaphore.release();
  18. }
  19. }