coffeescript中的异步函数

时间:2018-05-23 20:37:08

标签: function asynchronous web coffeescript

我正在尝试像以下代码块一样异步执行函数:

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”未定义。

有什么想法吗?

0 个答案:

没有答案