geo.addLocation('Toronto', {latitude: 43.6667, longitude: -79.4167}, function(err, reply){
if(err) console.error(err)
else console.log('added location:', reply)
})
const addLocation = (city, coord) => new Promise((resolve, reject) => {
geo.addLocation(city, coord, (err, reply) => {
if (err) reject(err)
else resolve(reply)
})
})
try {
const reply = await addLocation('Toronto', {latitude: 43.6667, longitude: -79.4167})
console.log('added location:', reply)
} catch (err) {
console.error(err)
}
const api = (isError = false, callback) => !isError
? callback(null, { code: 200 })
: callback(new Error(), null);
const promisify = (handle = () => {}) => (...args) => new Promise((resolve, reject) => {
handle(...args, (error, data) => {
if (error) {
reject(error);
} else {
resolve(data);
}
});
});
promisify(api)(true).then(data => {
console.log('data', data);
}).catch(error => {
console.log('error', error);
});