public function batch( $parallelRequests = null, callable $callback = null ) {
        /** @noinspection PhpParamsInspection */
        if( !isset( $callback ) && is_callable( $parallelRequests )) {
            $callback = $parallelRequests;
            $parallelRequests = null;
        }

        if( is_null( $parallelRequests )) {
            $parallelRequests = 6;
        }

        $size = $this->maxPageSize();

        $firstPageResponse = $this->request( $this->createPaginatedRequestQuery( 0, $size ) );
        $header_values = $firstPageResponse->getResponse()->getHeader('X-Result-Total');
        $total = array_shift($header_values);

        call_user_func( $callback, $firstPageResponse->json() );
        unset( $firstPageResponse );

        $lastPage = ceil( $total / $size );

        for( $page = 1; $page < $lastPage; ) {
            $batchRequests = [];

            for( $batchPage = 0; $batchPage < $parallelRequests && $page + $batchPage < $lastPage; $batchPage++ ) {
                $batchRequests[] = $this->createPaginatedRequestQuery( $page + $batchPage, $size );
            }

            $responses = $this->requestMany( $batchRequests );

            foreach( $responses as $response ) {
                call_user_func( $callback, $response->json() );
            }

            unset( $responses );

            $page += $parallelRequests;
        }
    }