Hi all,
I’m currently developing a custom core resource for a community. I’m needing to make contact with a database asynchronously. This needs to be done so that I can ensure the data has actually returned before I start digesting it.
However, it seems that whenever I’m using an await
keyword, I’m experiencing a block. Now, I know that’s the point of await, that the current process should be blocked until the await process has been cleared.
I’m using GHMatti’s MySQL dependency here.
public async Task<Dictionary<int, object>> ExecuteSelectAsync (string statement)
{
var tcs = new TaskCompletionSource<Dictionary<int, object>>();
int i = 0;
Exports["ghmattimysql"].execute(
statement,
new Action<dynamic>(s =>
{
// Convert response into a workable object
List<Object> responses = s;
// New empty dictionary, which will eventually be returned
Dictionary<int, object> responseData = new Dictionary<int, object>();
// Manipulation of data into the format I desire
// Setting the result of the TCS
tcs.SetResult(responseData);
})
);
// Await for the TCS to complete
var response = await tcs.Task;
Utility.LogDebug("Database", "Returning select execution response");
return response;
}
Should I be using await BaseScript.Delay(100)
somewhere? I’ve experimented with using it, but I find that results vary from nothing to the base script continuing to execute.
How can I make sure that the script waits for the TCS data, but doesn’t freeze up the server?
Thanks