Skip to content

Commit

Permalink
p1: support custom promise API
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Chi <[email protected]>
  • Loading branch information
skyzh committed Sep 9, 2023
1 parent 03b9be6 commit 558030f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
10 changes: 10 additions & 0 deletions src/include/storage/disk/disk_scheduler.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,16 @@ class DiskScheduler {
*/
void StartWorkerThread();

using DiskSchedulerPromise = std::promise<bool>;

/**
* @brief Create a Promise object. If you want to implement your own version of promise, you can change this function
* so that our test cases can use your promise implementation.
*
* @return std::promise<bool>
*/
auto CreatePromise() -> DiskSchedulerPromise { return {}; };

private:
/** Pointer to the disk manager. */
DiskManager *disk_manager_ __attribute__((__unused__));
Expand Down
4 changes: 2 additions & 2 deletions test/storage/disk_scheduler_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ TEST(DiskSchedulerTest, DISABLED_ScheduleWriteReadPageTest) {

std::strncpy(data, "A test string.", sizeof(data));

std::promise<bool> promise1;
auto promise1 = disk_scheduler->CreatePromise();
auto future1 = promise1.get_future();
std::promise<bool> promise2;
auto promise2 = disk_scheduler->CreatePromise();
auto future2 = promise2.get_future();

disk_scheduler->Schedule({/*is_write=*/true, reinterpret_cast<char *>(&data), /*page_id=*/0, promise1});
Expand Down

0 comments on commit 558030f

Please sign in to comment.