private static function terminate(): Promise
    {
        if (self::$onClose === null) {
            return Promise\any([]);
        }

        if (self::$signalWatchers) {
            foreach (self::$signalWatchers as $watcher) {
                Loop::cancel($watcher);
            }
        }

        $onClose = self::$onClose;
        self::$onClose = null;

        $promises = [];
        foreach ($onClose as $callable) {
            $promises[] = call($callable);
        }

        return Promise\any($promises);
    }