if ( opts ) { opts.sync = false; }
return new Promise( ( resolve, reject ) => {
db.put( key, value, opts, ( err ) => {
if ( err ) return reject( err );
resolve( err);
});
});
}
async function dbputA( key, value) {
let err
try{
err = await dbput(key,value)
} catch(e){err=e}
return {err:err}
}
function dbget( key, opts ) {
return new Promise( ( resolve, reject ) => {
db.get( key, opts, ( err, val ) => {
if ( err ) return reject( err );
resolve( val );
});
});
}
async function dbgetA( key) {
let err,val
try{
val= await dbget(key)
} catch(e){err=e}
return {err:err,val:val}
}
const key = "key1"
const val = "val1"
var res=dbputA(key,val)
console.log(res)
res=dbgetA(key)
console.log(res)
Promise { <pending> }
Promise { <pending> }
Help please, почему pending?
var res=dbputA(key,val) console.log(res) res.then(r=>console.log(r)) setTimeout(()=>console.log(res),9999) ?
https://learn.javascript.ru/promise
Обсуждают сегодня