-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #240 from pavanvo/feat/non_blocking
Feat/non blocking for loading game info
- Loading branch information
Showing
4 changed files
with
107 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
#pragma once | ||
|
||
#include <functional> | ||
#include <thread> | ||
#include <utility> | ||
|
||
using std::function; | ||
using std::thread; | ||
|
||
namespace Shared{ namespace Util{ | ||
|
||
template<typename T> | ||
class CallBack { | ||
|
||
|
||
private: | ||
function<void()> _onThen = [](){}; | ||
function<T()> _mainFunc = [](){}; | ||
T _result; | ||
|
||
public: | ||
CallBack(function<T()> func){ | ||
_mainFunc = func; | ||
}; | ||
|
||
~CallBack() { | ||
//printf("CallBack::~CallBack p [%p]\n",this); | ||
}; | ||
|
||
void then(function<void()> onThen){ | ||
_onThen = onThen; | ||
}; | ||
|
||
T getResult(){ | ||
return _result; | ||
} | ||
|
||
void run(){ | ||
_result = _mainFunc(); | ||
_onThen(); | ||
}; | ||
}; | ||
|
||
template<> | ||
class CallBack<void> { | ||
|
||
private: | ||
function<void()> _onThen = [](){}; | ||
function<void()> _mainFunc = [](){}; | ||
|
||
public: | ||
CallBack(function<void()> func){ | ||
_mainFunc = func; | ||
}; | ||
|
||
~CallBack() { | ||
//printf("CallBack::~CallBack p [%p]\n",this); | ||
}; | ||
|
||
void then(function<void()> onThen){ | ||
_onThen = onThen; | ||
}; | ||
|
||
void run(){ | ||
_mainFunc(); | ||
_onThen(); | ||
}; | ||
}; | ||
|
||
}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters