I have a case which can be summarized like below:
class C
{
bool veryImportantFlag = false;
}
class B
{
C[] list;
}
class D
{
A a;
B b;
this ()
{
a = new A;
b = new B;
// add some C inside of b
}
void updateLoop()
{
//!! set some the veryImportantFlag = true
foo(b);
sleep(1.seconds);
}
void foo( B temp )
{
a.Finalize(temp);
}
}
class A
{
Tuple!(bool, vibe.core.concurrency.Future!(bool)) futureCancelSell;
void Finalize( B list )
{
if ( !futureCancelSell[0] || futureCancelSell[1].ready() )
{
futureCancelSell[0] = true;
futureCancelSell[1] = vibe.core.concurrency.async( &CheckPreviousSells, list);
}
}
void CheckPreviousSells( B param )
{
param.list.filter!(a => a.veryImportantFlag);
}
}
Very strange sometimes even the "veryImportantFlag" is true inside "CheckPreviousSells" function
param.list.filter!(a => a.veryImportantFlag);
Returns empty list. This problem does not happen if I remove async call and make it a blocking call.
I am curious if this something related with passing the value with reference. Do you guys have any idea why I am habing this problem.
Also not important but whenever I need to make async calls I am needing to hold a Tuple like
Tuple!(bool, vibe.core.concurrency.Future!(bool)) futureCancelSell;
Is there any better solution for this? Can I avoid the boolean somehow?