def join(self, timeout: Optional[float] = None):
        """
        Can be invoked only by a process: makes it join the queue. The order token is computed once for the process,
        before it is enqueued. Another process or event, or control code of some sort, must invoke method `pop()` of the
        queue so that the process can eventually leave the queue and carry on with its execution.

        :param timeout:
            If this parameter is not ``None``, it is taken as a delay at the end of which the process times out, and
            leaves the queue forcibly. In such a situation, a :py:class:`Timeout` exception is raised on the process.
        """
        class CancelBalk(Interrupt):
            pass

        self._counter += 1
        if _logger is not None:
            self._log(INFO, "join")
        heappush(self._waiting, (self._get_order_token(self._counter), Process.current()))

        proc_balk = None
        if timeout is not None:
            def balk(proc):
                nonlocal proc_balk
                try:
                    advance(cast(float, timeout))
                    proc.interrupt(Timeout())
                except CancelBalk:
                    pass
                finally:
                    proc_balk = None

            # The balking process is started here.
            proc_balk = add(balk, Process.current())

        try:
            pause()
        except Interrupt:
            current = Process.current()
            for index in reversed([i for i, (_, proc) in enumerate(self._waiting) if proc is current]):
                del self._waiting[index]
            heapify(self._waiting)
            raise
        finally:
            # Three situations can prompt a process to exit a queue:
            #
            # 1. The process is pop()ped out of the queue by a peer.
            # 2. The process balk()s out after a timeout.
            # 3. The process leaves the queue because of a distinct interrupt (besides CancelBalk).
            #
            # In cases 1 and 3, the balking process has never exited and is still in the advance() call. In both these
            # cases, the balking process should itself be interrupted, otherwise it may prompt the balking of a future
            # queue traversal. However, if we exit the queue because of case no. 2, the balking process is finished.
            # Interrupting it would do no harm (it has been tested by accident), but we mean to be deliberate about when
            # this interruption is necessary. So we perform the interrupt of the balking process only in cases 1 and 3;
            # in case 2, the balk() function exits, thereby clearing the reference we have here to it. Do remark that
            # whenever a timeout is not set, proc_balk remains None all the way, reducing the situation to case 1.
            if proc_balk is not None:
                proc_balk.interrupt(CancelBalk())
Can be invoked only by a process: makes it join the queue. The order token is computed once for the process,
        before it is enqueued. Another process or event, or control code of some sort, must invoke method `pop()` of the
        queue so that the process can eventually leave the queue and carry on with its execution.

        :param timeout:
            If this parameter is not ``None``, it is taken as a delay at the end of which the process times out, and
            leaves the queue forcibly. In such a situation, a :py:class:`Timeout` exception is raised on the process.