@param mixed $priority
@throws Event\InvalidPriorityException

@return Event
518676
public function setPriority($priority) {
        if (!$this->isValidPriority($priority)) {
            throw new InvalidPriorityException('Priority must be on of Event::PRIORITY_*');
        }
        $this->priority = $priority;

        return $this;
    }
230133
public function addListener(EventListener $listener, $priority = 0, $important = false)
    {
        if ($listener === $this) {
            throw new EventException("Adding self as listener in 'Events\EventDispatcher' would cause an infinite loop");
        }
        $priority = -$priority;
        while (isset($this->listeners[$priority])) {
            $priority += $important ? -1 : 1;
        }
        $this->listeners[$priority] = $listener;
        ksort($this->listeners);
        $this->processStackedEvents();
        return $this;
    }
136375
public function setPriority($name, $priority)
    {
        if (!isset($this->items[$name])) {
            throw new \Exception("item $name not found");
        }

        $this->items[$name]['priority'] = (int) $priority;
        $this->sorted                   = false;

        return $this;
    }
472498
public function add($entry, $priority = self::DEFAULT_PRIORITY)
    {
        if (isset($this->entryClass) && !($entry instanceof $this->entryClass)) {
            throw new InvalidObjectClassException($this->entryClass, get_class($entry));
        }
        $this->entries[] = ['data' => $entry, 'priority' => $priority];
        $this->sorted = false;
        return $this;
    }
826584
public function once(string $eventName, callable $callBack, int $priority = 100)
    {
        $wrapper = null;
        $wrapper = function () use ($eventName, $callBack, &$wrapper) {
            $this->removeListener($eventName, $wrapper);

            return \call_user_func_array($callBack, \func_get_args());
        };

        $this->on($eventName, $wrapper, $priority);
    }
573996
public function attach(EventManagerInterface $events, $priority = 1)
    {
        $events->attach(PageEvent::EVENT_ADD_PRE, [$this, 'setStandardParams']);
        $events->attach(PageEvent::EVENT_EDIT_PRE, [$this, 'setStandardParams']);
        $events->attach(PageEvent::EVENT_APPROVED, [$this, 'setStandardParams']);

        $events->attach(PageEvent::EVENT_ADD_PRE, [$this, 'setSlug']);
        $events->attach(PageEvent::EVENT_EDIT_PRE, [$this, 'setSlug']);
        $events->attach(PageEvent::EVENT_APPROVED, [$this, 'setSlug']);

        $events->attach(PageEvent::EVENT_APPROVED, [$this, 'saveNavigation']);

        $events->attach(PageEvent::EVENT_APPROVED, [$this, 'updateCache']);
    }
1001388
public function setEventPriority($name, AnObjectHandable $listener, $priority)
    {
        if (isset($this->_listeners[$name])) {
            $this->_listeners[$name]->setPriority($listener, $priority);
        }
        
        return $this;
    }
1130072
protected function createQueue($priority)
    {
        if (!$this->queues[$priority]) {
            $this->queues[$priority] = new \SplQueue();
            $this->queues[$priority]->setIteratorMode(\SplQueue::IT_MODE_DELETE);
        }

        return $this->queues[$priority];
    }
1352106
public function attachEvent($event, $handler, $priority = 0)
    {
        $this->eventDispatcher->addListener($event, $handler, $priority);
        return $this;
    }
1024598
public function setPriority($priority, $retry = null, $expire = null) {
		// Sanity checks
		if (!is_int($priority)) throw new \InvalidArgumentException('priority needs to be a valid integer between -1 and 2');
		if ($retry) {
			if (!is_int($retry)) return \InvalidArgumentException('retry is not a number');
			if (($retry<30) || ($retry>86400)) {
				throw new \InvalidArgumentException('retry needs to be between 30 and 86400');
			}
			$this->retry = $retry;
		}
		if ($expire) {
			if (!is_int($expire)) return \InvalidArgumentException('expire is not a number');
			if (($expire<0) || ($expire>86400)) {
				\InvalidArgumentException('expire between 0 and 86400');
			}
			$this->expire = $expire;
		}
		if ($priority == 2) {
			if ((!$retry) || (!$expire)) {
				throw new \InvalidArgumentException('retry and expire need to be provided for priority 2');
			}

		}

		if (($priority<-1) || ($priority>2)) {
			throw new \InvalidArgumentException('priority is outside of valid rangeneeds to be a valid integer between -1 and 2');
		}
		
		$this->priority = $priority;
		return true;
	}
484362
public function on($event_name, $callback, $priority = 100) {
	    	if(!is_callable($callback)){
	    		throw new \InvalidArgumentException("Argument 'callback' is not callable.");
	    	}

	        if (!isset($this->listeners[$event_name])) {
	            $this->listeners[$event_name] = array(
	                true,  // If there's only one item, it's sorted
	                array($priority),
	                array($callback)
	            );
	        } else {
	            $this->listeners[$event_name][0] = false; // marked as unsorted
	            $this->listeners[$event_name][1][] = $priority;
	            $this->listeners[$event_name][2][] = $callback;
	        }
	    }
375972
public function attach(ChainEventInterface $event, $priority = 0)
    {
        $this->queue->insert($event, $priority);
        return $this;
    }
566717
protected function getActualPriority(string $eventName, $priority): int
    {
        if (\is_int($priority)) {
            return $priority;
        }
        if (!\in_array($priority, ['first', 'last'], \true)) {
            $mess = 'Unknown priority was given only "first", "last", or integer may be used';
            throw new \InvalidArgumentException($mess);
        }
        $listenerM = parent::getActualPriority($eventName, $priority);
        if ($priority === 'first') {
            $serviceM = \array_key_exists($eventName, $this->serviceListeners)
                ? \max(\array_keys($this->serviceListeners[$eventName])) + 1 : 1;
            return ($listenerM > $serviceM) ? $listenerM : $serviceM;
        }
        $serviceM = \array_key_exists($eventName, $this->serviceListeners)
            ? \min(\array_keys($this->serviceListeners[$eventName])) - 1 : -1;
        return ($listenerM < $serviceM) ? $listenerM : $serviceM;
    }
304996
public function priority($level = 3)
    {
        $this->callbacks[] = function ($message) use ($level) {
            $message->setPriority($level);
        };

        return $this;
    }
655102
public function setHandlerPriority(KCommandHandlerInterface $handler, $priority)
    {
        $this->__queue->setPriority($handler, $priority);
        return $this;
    }
1171712
public function push($value, int $priority)
    {
        $this->checkCapacity();

        // Add new leaf, then sift up to maintain heap,
        $this->heap[] = new PriorityNode($value, $priority, $this->stamp++);
        $this->siftUp(count($this->heap) - 1);
    }
65189
public function once($event, $listener, int $priority = Priority::NORMAL)
    {
        $this->addListener($event, $listener, $priority, true);
    }