Couchdb httpinvoke和PockDB承诺暂停
在进行httpinvoke调用之后,我需要加载couchDB,但是承诺没有传递Couchdb httpinvoke和PockDB承诺暂停,couchdb,promise,Couchdb,Promise,在进行httpinvoke调用之后,我需要加载couchDB,但是承诺没有传递 createDB: function() { var db = new PouchDB('options'); db.info().then(function (info){ if(info.doc_count <= 10000) { var db = new PouchDB('options'); db.destroy().the
createDB: function() {
var db = new PouchDB('options');
db.info().then(function (info){
if(info.doc_count <= 10000) {
var db = new PouchDB('options');
db.destroy().then(function(info){
httpinvoke('http://localhost:9080/secure/sync.form','GET');
}).then(function (res){
console.log(JSON.stringify(res)); //This never gets called but if I move this then() block to httpinvoke(xxx).then() it does get called
}).catch(function(err){
console.log(JSON.stringify(err));
});
}
});
}
createDB:function(){
var db=新数据库(“选项”);
db.info().then(函数(info){
if(info.doc_count通过返回值承诺链。如果你想让承诺有意义,你必须返回它。承诺代表一个值+时间,你的httpinvoke
调用不返回类似于synchronus函数不返回
createDB: function() {
var db = new PouchDB('options');
db.info().then(function (info){
if(info.doc_count <= 10000) {
var db = new PouchDB('options');
db.destroy().then(function(info){
return httpinvoke('...','GET'); // NOTE THE RETURN
}).then(function (res){
console.log(res); // console already shows JSON
}); // no need to `catch anyway`, errors are errors let's not suppress.
}
});
}
createDB:function(){
var db=新数据库(“选项”);
db.info().then(函数(info){
if(info.doc_count)这是我之前想的。我尝试返回httpinvoke()调用。但是它返回一个函数(){/*jshint expr:true/cb&&cb(newerror('abort');/jshint expr:false*/try{xhr.abort();}catch(err){}。相反,如果我更改它并使其成为httpinvoke(“…”,“GET”)。然后(函数(res){console.log(res)});效果很好。只是当我尝试链接承诺时,它没有通过…?这是非常不可能的。它可能只是用函数解析吗?如果返回httpinvoke(…),会发生什么情况。然后(函数(r){返回r;})
并链接到该库?我认为这将起作用,因为我们将显式返回ajax响应。我刚刚将httpinvoke库更改为reqwest库,代码工作正常。因此httpinvoke库可能存在一些错误。可能会在稍后报告。当然,我必须返回调用,但它与请求一起工作。感谢您的支持答复。