我正在尝试像以下代码块一样异步执行函数:
asyncSearch = (e) ->
await search(e)
$("#main-search").on("input", (e) ->
clearTimeout(delayTimer)
delayTimer = setTimeout( ->
asyncSearch(e)
, 100)
)
#Method for searching
search = (input) ->
new Promise (resolve) ->
loadedAlbums = 40
toggleAlbum(sibling: undefined)
//more code
....
然而,这并不像我期望的那样进行编译。相反,它正在编译:
asyncSearch = function(e) {
return await(search(e));
};
$("#main-search").on("input", function(e) {
clearTimeout(delayTimer);
return delayTimer = setTimeout(function() {
return asyncSearch(e);
}, 100);
});
search = function(input) {
return new Promise(function(resolve) {
var album, doSearch, inputValues, k, l, len, m, rawInput, ref, tempAlbums;
loadedAlbums = 40;
//more code
...
我之后得到的错误可以理解为一个ReferenceError,其中“await”未定义。
有什么想法吗?