Skip to content

Promise.all error #1953

Open
Open

Description

@jzzqwhw
(async () =>{
        async function fun1(){
            let f1 = "D:\\a1.xlsx"
            const res1 = await alasql.promise(`select * from xlsx(?) limit 100000`, [f1])
            return res1
        }

        async function fun2(){
            let f2 = "D:\\a2.xlsx"
            const res2 = await alasql.promise(`select * from xlsx(?) limit 100001`, [f2])
            return res2
        }

        try{
            const orderData = await Promise.all([fun1(), fun2()])    
            console.log(orderData)
        }catch(error){
            console.error(error);
        }finally{
            console.log('end');
        }
    })() 

I have an issue where I've created two asynchronous functions, fun1 and fun2, and I want to execute them in batch using Promise.all, passing parameters f1 and f2 to the xlsx(?) placeholder.

When running these functions individually, the query results are correct.

However, when I put them into Promise.all, no results are returned, and no errors are thrown.

After repeated testing, I found that if there is nothing after xlsx(?) in Promise.all, no results are returned. But if I add a limit and the number after limit is different for each function, the correct results are obtained. Yet, if the numbers after limit are the same, no results are returned again.

For example, in the code above, if both are limit 1000, no results are returned. But if one is limit 1000 and the other is limit 1001, the correct results can be obtained.

What could be the reason for this?

Activity

  1. mathiasrw commented on Aug 4, 2024

    @mathiasrw
    Member

    Hmmm. Very strange. I am wondering how the timing of these two functions might affect each other. Hmmmmmmm...

    Im wondering if running async commands via a queue instead will affect this. It will effectively make multiple queries run in sequense, but getting incorrect results is worse.

  2. znenuko commented on Aug 21, 2024

    @znenuko

    Hi,

    I reviewed the issue you reported and made some adjustments to the code to address it. Here’s the updated solution:

    (async () => {
        async function fun1() {
            let f1 = "D:\\a1.xlsx";
            try {
                console.log('Running fun1 with', f1);
                const res1 = await alasql.promise(`select * from xlsx(?) limit 100000`, [f1]);
                console.log('Result from fun1:', res1);
                return res1;
            } catch (error) {
                console.error('Error in fun1:', error);
                throw error; // Re-throw to be caught in the main try-catch block
            }
        }
    
        async function fun2() {
            let f2 = "D:\\a2.xlsx";
            try {
                console.log('Running fun2 with', f2);
                const res2 = await alasql.promise(`select * from xlsx(?) limit 100001`, [f2]);
                console.log('Result from fun2:', res2);
                return res2;
            } catch (error) {
                console.error('Error in fun2:', error);
                throw error; // Re-throw to be caught in the main try-catch block
            }
        }
    
        try {
            console.log('Starting batch execution');
            const orderData = await Promise.all([fun1(), fun2()]);
            console.log('Batch results:', orderData);
        } catch (error) {
            console.error('Error in Promise.all:', error);
        } finally {
            console.log('End');
        }
    })();
    

    Explanation:

    Main File: The updated code performs queries on Excel files with different limits in parallel.
    Error Handling: Added additional logging to detect and handle errors during execution.
    Testing: Make sure to test the functions individually and adjust limits if needed.

  3. sharmaut commented on Aug 7, 2025

    @sharmaut

    Hi, I'm new to open source and would like to work on this issue. Is this task still available? I've read the guidelines and would appreciate any guidance you can offer.

  4. mathiasrw commented on Nov 19, 2025

    @mathiasrw
    Member

    Yep. its available.

  5. imsanupm commented on Feb 28, 2026

    @imsanupm

    Hi, I’m interested in working on this issue. If it’s not actively being worked on, could you please assign it to me? I’m ready to start.

  6. mathiasrw commented on Sep 10, 2026

    @mathiasrw
    Member

    @imsanupm How is progress? Should I move this to some one else?

  7. added this to the Focus milestone on Oct 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions