AsyncTaskPool working/example?

I am trying to use this api as follows but it’s giving me the following error:

First I don’t know what should be in callBack params. Secondly, I think error is not just this.

.
.
.
auto atp = AsyncTaskPool::getInstance();
atp->enqueue(AsyncTaskPool::TaskType::TASK_OTHER, CC_CALLBACK_1(HomeScene::resourceDidLoad, this), 0, [this]() {
        this->audio->preloadEffect("audio_file_path.wav");
    });
.
.
.

void HomeScene::resourceDidLoad(cocos2d::Ref *sender, int index) {
	CCLog("................%d................", index);
}

error: no matching function for call to 
'cocos2d::AsyncTaskPool::enqueue(cocos2d::AsyncTaskPool::TaskType, std::_Bind_helper<false, void (SplashScene::*)(cocos2d::Ref*, int), SplashScene*, const std::_Placeholder<1>&, int>::type, void*, SplashScene::init()::<lambda()>)'
    });

Hey @slackmoehrle
Any idea where can I find working example for it. I couldn’t find it in cppTests

In my projects i do something like this:

void ConfigManager::endLoadFile(const Configs *configs, const LoadCallBack callback, void*)
{
}

void ConfigManager::asyncLoadFile(const File file, const LoadCallBack callback/* = nullptr*/)
{
  auto async = cocos2d::AsyncTaskPool::getInstance();
  auto configs = new (std::nothrow) Configs();
  async->enqueue(
    cocos2d::AsyncTaskPool::TaskType::TASK_IO,
    std::bind(&ConfigManager::endLoadFile, this, configs, callback, std::placeholders::_1),
    nullptr,
    [file, configs] ()
    {

    }
  );
}
1 Like

Hey @serjdawg
Thanks for your reply.
This worked.
But I wanted to also learn what is API’s 3rd argument. I meant how to pass the callback params?
Also, do I need to destroy the instance of AsyncTaskPool once I am enquing something?

My final code.

.
.
    auto atp = AsyncTaskPool::getInstance();
    atp->enqueue(AsyncTaskPool::TaskType::TASK_OTHER, std::bind(&HelloWorld::resourceDidLoad, this, 0), nullptr,
    		[this]() {
    			this->audio->preloadEffect("audio/whoosh4.wav");
			}
    );


.
.
.
void HelloWorld::resourceDidLoad(int index) {
	CCLog("................%d................", index);
}


Did you figure it out yet?

Is it possible to create a new scene in a background thread?

1 Like

Do not forget to delete “configs” in callback

did you find out the way?