'use strict';
const Promise = require('bluebird');
Promise.map(urls, async function (url, index) {
try {
// Здесь ваш код, который берет url и сохраняет изображение
// Об async/await можно почитаь здесь - https://learn.javascript.ru/async-await
} catch (e) {
console.error(e);
}
}, { concurrency: 10 }).catch(console.error);
С чем это связано?
Each ArrayList instance has a capacity. The capacity is the size of the array used to store the elements in the list. It is always at least as large as the list size. As elements are added to an ArrayList, its capacity grows automatically. The details of the growth policy are not specified beyond the fact that adding an element has constant amortized time cost.
An application can increase the capacity of an ArrayList instance before adding a large number of elements using the ensureCapacity operation. This may reduce the amount of incremental reallocation.
public ListIterator<E> listIterator(int index) {
checkPositionIndex(index);
return new ListItr(index);
}
// ...
private class ListItr implements ListIterator<E> {
private Node<E> lastReturned = null;
private Node<E> next;
private int nextIndex;
private int expectedModCount = modCount;
ListItr(int index) {
// assert isPositionIndex(index);
next = (index == size) ? null : node(index);
nextIndex = index;
}
public boolean hasNext() {
return nextIndex < size;
}
public E next() {
checkForComodification();
if (!hasNext())
throw new NoSuchElementException();
lastReturned = next;
next = next.next;
nextIndex++;
return lastReturned.item;
}
private class Itr implements Iterator<E> {
int cursor; // index of next element to return
int lastRet = -1; // index of last element returned; -1 if no such
int expectedModCount = modCount;
public boolean hasNext() {
return cursor != size;
}
@SuppressWarnings("unchecked")
public E next() {
checkForComodification();
int i = cursor;
if (i >= size)
throw new NoSuchElementException();
Object[] elementData = ArrayList.this.elementData;
if (i >= elementData.length)
throw new ConcurrentModificationException();
cursor = i + 1;
return (E) elementData[lastRet = i];
}
var buffer = new byte[16];
var offset = 0;
var read = 0;
while(offset < buffer.Length && (read = stream.Read(buffer, offset, buffer.Length - offset)) > 0)
{
offset += read;
}
if (offset < buffer.Length) { /* EOS */ }
async getAll(req, res) {
try {
const { rows, rowCount } = await db.query(query)
return res.status(200).send({ rows, rowCount })
} catch (error) {
return res.status(400).send(error)
}
}
В чем моя проблема?)
какие книги ставят голову на место в этом плане?
Почему?