sms516
3/20/2019 - 10:29 PM

Promise & async await

The shows how to use a promise with .then and await

export const wait = (src) => {
	return new Promise(function(resolve, reject) {
		let img = new Image()
		img.onload = () => resolve(true)
		img.onerror = reject
		img.src = src
	});
}

export const initBookmarkCreate = (src) => async dispatch => {
	try {
		let validURL = await wait(src);
		console.log(validURL);
	} catch (err) {
		console.error(err);
	}

	wait(src).then(success => {
		console.log(success)
	}).catch(err => {
		console.log(err)
	})
}