Using async requires async function, but my function is async

前端 未结 4 766
没有蜡笔的小新
没有蜡笔的小新 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:43

    You don't read that error message right: the problem isn't the function you're calling but the function you're in.

    You may do

    (async function(){
        await dbc.solve(img);
        // more code here or the await is useless
    })();
    

    Note that this trick should soon enough not be needed anymore in node's REPL: https://github.com/nodejs/node/issues/13209

提交回复
热议问题