Using async requires async function, but my function is async

前端 未结 4 801
没有蜡笔的小新
没有蜡笔的小新 2021-01-18 07:44

I\'m adapting a library that uses callback to use Promises. It\'s working when I use then(), but it doesn\'t work when I use await.



        
4条回答
  •  渐次进展
    2021-01-18 08:21

    You may not need async await abstraction really. Why don't you just simply promisify dbc.solve() function with a promisifier like;

    function promisify(f){
      return data => new Promise((v,x) => f(data, (err, id, sol) => err ? x(err) : v({i:id, s:solution})));
    }
    

    You will have a promisified version of your dbc.solve() and if it doesn't fire an error you will be returned with an object like {i:id, s: solution} at it's then stage.

提交回复
热议问题