Switch to async/await

This commit is contained in:
Jonathan Cremin 2018-04-14 00:18:48 +01:00
parent 87459b2acc
commit 18021e0ef8
10 changed files with 53 additions and 8837 deletions

View file

@ -26,10 +26,10 @@ const apiRoot = 'https://www.googleapis.com/youtube/v3';
// retryCount: 10,
// });
export function* lookupId(id) {
export async function lookupId(id) {
const path = `/videos?part=snippet%2CcontentDetails&id=${id}&key=${credentials.key}`;
try {
const result = yield request.get(apiRoot + path);
const result = await request.get(apiRoot + path);
const item = result.body.items[0].snippet;
const duration = toSeconds(ptParse(result.body.items[0].contentDetails.duration));
@ -73,7 +73,7 @@ export function* lookupId(id) {
}
}
export function* search(data) {
export async function search(data) {
let query;
const type = data.type;
@ -84,7 +84,7 @@ export function* search(data) {
}
const path = `/search?part=snippet&q=${encodeURIComponent(query)}&type=video&videoCaption=any&videoCategoryId=10&key=${credentials.key}`;
const result = yield request.get(apiRoot + path);
const result = await request.get(apiRoot + path);
const item = result.body.items[0];
if (!item) {