Using default std::allocator impl, but assuming user can define their own allocate/deallocate methods
| 53 | // Using default std::allocator impl, but assuming user can define their own |
| 54 | // allocate/deallocate methods |
| 55 | class CustomAllocWorker : public AsyncWorker { |
| 56 | using Allocator = std::allocator<CustomAllocWorker>; |
| 57 | |
| 58 | public: |
| 59 | CustomAllocWorker(Function& cb) : AsyncWorker(cb){}; |
| 60 | static void DoWork(const CallbackInfo& info) { |
| 61 | Function cb = info[0].As<Function>(); |
| 62 | Allocator allocator; |
| 63 | CustomAllocWorker* newWorker = allocator.allocate(1); |
| 64 | std::allocator_traits<Allocator>::construct(allocator, newWorker, cb); |
| 65 | newWorker->Queue(); |
| 66 | } |
| 67 | |
| 68 | protected: |
| 69 | void Execute() override {} |
| 70 | void Destroy() override { |
| 71 | assert(this->_secretVal == 24); |
| 72 | Allocator allocator; |
| 73 | std::allocator_traits<Allocator>::destroy(allocator, this); |
| 74 | allocator.deallocate(this, 1); |
| 75 | } |
| 76 | |
| 77 | private: |
| 78 | int _secretVal = 24; |
| 79 | }; |
| 80 | |
| 81 | class TestWorker : public AsyncWorker { |
| 82 | public: |
nothing calls this directly
no outgoing calls
no test coverage detected