1//************************************ bs::framework - Copyright 2018 Marko Pintera **************************************//
2//*********** Licensed under the MIT license. See LICENSE.md for full terms. This notice is not to be removed. ***********//
3#include "Utility/BsDeferredCallManager.h"
4
5namespace bs
6{
7 void DeferredCallManager::queueDeferredCall(std::function<void()> func)
8 {
9 mCallbacks.push_back(func);
10 }
11
12 void DeferredCallManager::_update()
13 {
14 while(!mCallbacks.empty())
15 {
16 // Copy because callbacks can be queued within callbacks
17 Vector<std::function<void()>> callbackCopy = mCallbacks;
18 mCallbacks.clear();
19
20 for(auto& call : callbackCopy)
21 {
22 call();
23 }
24 }
25 }
26
27 // Declared in BsPrerequisites.h
28 void deferredCall(std::function<void()> callback)
29 {
30 DeferredCallManager::instance().queueDeferredCall(callback);
31 }
32}