coco2dx 线程池AsyncTaskPool的使用方法

AsyncTask是什么呢?它是对线程池和Handler的封装;用线程池来挺处理后台任务,用Handler来处理与UI的交互。

struct AsyncData
	{		
		std::string zipFile;//zip包
		bool succeed;
	};
	AsyncData* asyncData = new AsyncData;	
	asyncData->zipFile = zip;
	asyncData->succeed = false;

	//解压成功后调用此回调方法
	std::function decompressFinished = [this](void* param) {
		auto dataInner = reinterpret_cast(param);
		delete dataInner;
	};
	AsyncTaskPool::getInstance()->enqueue(AsyncTaskPool::TaskType::TASK_OTHER, decompressFinished, (void*)asyncData, [this, asyncData]() {
		// Decompress all compressed files		
		if (decompress(asyncData->zipFile))//解压中......解压完成后会调用decompressFinished回调方法

		{
			asyncData->succeed = true;
		}
		_fileUtils->removeFile(asyncData->zipFile);
	});


你可能感兴趣的:(cocos2d-x)