'doPost(e) how to immediately response HTTP 200 OK, then do long time function

In Google App Script, need to send a HTTP received code within 3 seconds.

If there is no 3-second time-out:

function doPost(e) {
    //do stuff
    long_time_function ();
    //can response received simply with this
    //this will auto response received HTTP code: 200 to the request
    return ContentService.createTextOutput(); 
}  

Now with 3-second time-out requirement: within 3s if not sending a HTTP received code, the waiting server will trigger an error.

function doPost(e) {
    //quickly response received?
    //then do stuff
    function longtime() {//long time job }
}

I tried googling but couldn't find any workaround without using external libraries:

I tried:

    function doPost(e) {
        //using
        ContentService.createTextOutput();
        //or tried with UrlFetchApp
        UrlFetchApp.fetch(response_url, ops);

        Utilities.sleep(8000);//test
       //then do stuff
        function longtime() {//long time job }
    }

But still could not fully the 3s time-out requirement.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source