-
Notifications
You must be signed in to change notification settings - Fork 11
promise
mtanksl edited this page Apr 22, 2023
·
2 revisions
Instead of using .NET's Task Parallel Library, I'll be using my own custom class to represent asynchronous operation. It's all wrapped in the Promise
and PromiseResult<>
classes. If you know how to use .NET's Task
and Task<>
classes, it is the same.
For performance reasons and for simplicity. Promise is lighter and simpler. When a scheduled event is needed, it will be automatically dispatched to the server's scheduler thread
. Once it expires, it will automatically dispatch all the actions to the main server's (single thread) dispatcher thread
. We don't want to deal with concurrency problems, do we?
//...
Promise.Delay("CancellationKey", TimeSpan.FromSeconds(10) ).Then( () =>
{
//...
return Promise.Completed;
} );
or
public async Promise SomeMethod()
{
//...
await Promise.Delay("CancellationKey", TimeSpan.FromSeconds(10) );
//...
}