亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

使用承諾值的異步函數

使用承諾值的異步函數

呼喚遠方 2021-07-12 12:51:10
所以我知道這個問題經常被問到,但我試圖檢索一個在承諾中創建的變量。我在這里看到的例子涉及調用 .then 并在那里使用數據,但是我想要做的涉及異步函數——我不能在 .then 塊中使用它。這是我的代碼。我正在使用 Asana API 調出到期任務列表。它成功地記錄了它。但是我想將最后一個塊中的列表值保存為我可以在其他地方使用的變量。const asana = require('asana');        const client = asana.Client.create().useAccessToken("xxx");      client.users.me()        .then(user => {            const userId = user.id;            // The user's "default" workspace is the first one in the list, though            // any user can have multiple workspaces so you can't always assume this            // is the one you want to work with.            const workspaceId = user.workspaces[0].id;            return client.tasks.findAll({              assignee: userId,              workspace: workspaceId,              completed_since: 'now',              opt_fields: 'id,name,assignee_status,completed'            });          })          .then(response => {            // There may be more pages of data, we could stream or return a promise            // to request those here - for now, let's just return the first page            // of items.            return response.data;          })          .filter(task => {            return task.assignee_status === 'today' ||              task.assignee_status === 'new';          })          .then(list => {            console.log (util.inspect(list, {              colors: true,              depth: null            }));          })          .catch(e => {            console.log(e);          });
查看完整描述

1 回答

  • 1 回答
  • 0 關注
  • 160 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號