public function write(array $queries, int $concurrency = 5) : array
    {
        $result = [];
        $openedStreams = [];

        foreach ($queries as $query) {
            $requests = function(Query $query) use(&$openedStreams) {
                if (!empty($query->getFiles())) {
                    foreach ($query->getFiles() as $file) {
                        /* @var FileInterface $file */
                        $headers = $this->getHeaders();

                        $uri = $this->buildRequestUri($query->getServer(), [
                            'query' => $query->getQuery()
                        ], $query->getSettings());

                        $stream = $file->open();
                        $openedStreams[] = $stream;

                        $request = new Request('POST', $uri, $headers, $stream);

                        yield $request;
                    }
                } else {
                    $headers = $this->getHeaders();

                    $uri = $this->buildRequestUri($query->getServer(), [], $query->getSettings());

                    $request = new Request('POST', $uri, $headers, gzencode($query->getQuery()));

                    yield $request;
                }
            };

            $queryResult = [];

            $pool = new Pool(
                $this->httpClient, $requests($query), [
                    'concurrency' => $concurrency,
                    'fulfilled' => function ($response, $index) use (&$queryResult, $query) {
                        $queryResult[$index] = true;
                    },
                    'rejected' => $this->parseReason($query),
                    'options' => array_merge([
                        'expect' => false
                    ], $this->options['write'] ?? []),
                ]
            );

            $promise = $pool->promise();

            try {
                $promise->wait();
            } catch (\Throwable $exception) {
                foreach ($openedStreams as $openedStream) {
                    $openedStream->close();
                }

                throw $exception;
            }

            ksort($result);

            foreach ($openedStreams as $openedStream) {
                $openedStream->close();
            }

            $result[] = $queryResult;
        }

        return $result;
    }