2
0

Semaphore.hx 499 B

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