TypeScript-เดี๋ยวก่อนสำหรับฟังก์ชันที่สมบูรณ์จนกว่าระหว่างประมวลผลต่อฟังก์ชัน

0

คำถาม

ฉันมีสองคนฟังก์ชัน:doAsyncStuff และ doNextStep. ยังไงฉันปลอดภัย doNextStep จะต้องถูกประหารเพียงหลังจาก doAsyncStuff คือเสร็จแล้ว?

ฉันพยายามอย่างนั้นแต่มันไม่ได้ช่วย: doAsyncStuff().then(_ => doNextStep());

async function doAsyncStuff() {
    if (vscode.workspace.workspaceFolders) {
        vscode.workspace.workspaceFolders.forEach(async (e) => {
            for (const [name, type] of await vscode.workspace.fs.readDirectory(e.uri)) {
                console.log(name);
            }
        });
    
    }
    return true;
}

function doNextStep() {
    console.log('next step');
}
async-await typescript
2021-11-23 19:10:06
1

คำตอบที่ดีที่สุด

0

ขอบคุณมากสำหรับของคุณการตอบกลับที่ทางออกของ hotcakedev ทำงานออกมาจากกล่อง. สัญญาทั้ง(vscode.ขอบเขตสี.workspaceFolders.แผนที่(async...รอคำสั่ง))

และนี่คือวิธีที่มันดูเหมือน(ผลลัพธ์จากสถานการณ์ใช้ async recursive ฟังก์ชัน'readFolders'ซึ่งเป็นยังทำงานงั้น):

        await Promise.all(vscode.workspace.workspaceFolders.map(async x => {


            for (const [name, type] of await vscode.workspace.fs.readDirectory(x.uri)) {
               console.log(name);
            }
            // await readFolders(x.uri,x.uri.path);



        }));



        console.log('fin');
2021-11-23 21:44:01

ดีใจที่ช่วย!
hotcakedev

ในภาษาอื่นๆ

หน้านี้อยู่ในภาษาอื่นๆ

Русский
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................

ดังอยู่ในนี้หมวดหมู่

ดังคำถามอยู่ในนี้หมวดหมู่