xxxxxxxxxx
const someFunction = (myArray) => {
const promises = myArray.map(async (myValue) => {
return {
id: "my_id",
myValue: await service.getByValue(myValue)
}
});
return Promise.all(promises);
}
xxxxxxxxxx
const dummyfunction = async () => {
for (item of items) {
// Until promise returns,
// The loop waits here!
await turtle();
}
}
xxxxxxxxxx
const urls = [
'https://jsonplaceholder.typicode.com/todos/1',
'https://jsonplaceholder.typicode.com/todos/2',
'https://jsonplaceholder.typicode.com/todos/3'
];
async function getTodos() {
const promises = urls.map(async (url, idx) =>
console.log(`Received Todo ${idx+1}:`, await fetch(url))
);
await Promise.all(promises);
console.log('Finished!');
}
xxxxxxxxxx
const j = 10;
for (let i = 0; i < j; i++) {
asynchronousProcess(function() {
console.log(i);
});
}
xxxxxxxxxx
var j = 10;
for (var i = 0; i < j; i++) {
asynchronousProcess(i, function(cntr) {
console.log(cntr);
});
}
xxxxxxxxxx
someArray.forEach(function(item, i) {
asynchronousProcess(function(item) {
console.log(i);
});
});
xxxxxxxxxx
async def load_json_lines(stream_reader):
async for line in stream_reader:
yield json.loads(line)