admin管理员组

文章数量:1122826

I'm wondering if there is a way to run some async task in the background while other processing is happening in Hacklang, and then once the other processing is done, check if the result from the other async task is complete, and use the response if it is? There are some time sensitive things that need to be done, that can't be blocking.

public async function doStuff() {
   $background_res = doSomethingAsync();

   // do a bunch of important processing

   // get result of $background_res if it completed, if not move on
}

I'm wondering if there is a way to run some async task in the background while other processing is happening in Hacklang, and then once the other processing is done, check if the result from the other async task is complete, and use the response if it is? There are some time sensitive things that need to be done, that can't be blocking.

public async function doStuff() {
   $background_res = doSomethingAsync();

   // do a bunch of important processing

   // get result of $background_res if it completed, if not move on
}
Share Improve this question asked Nov 23, 2024 at 4:30 tallkid24tallkid24 1,8094 gold badges17 silver badges21 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

In Hack, you can await multiple tasks at once:

concurrent{
  $background_awaitable = await doSomethingAsync();
  $important_result = await importantProcessing();
}

However, this will wait until all are done before continuing. If you want to not wait until both are done, you will need to look into a separate threading library

本文标签: Running async task in the background in HacklangStack Overflow