Skip to content

Commit

Permalink
karm-base: Added errorIfCanceled() to Cancelation::Token.
Browse files Browse the repository at this point in the history
  • Loading branch information
sleepy-monax committed Dec 20, 2024
1 parent 7866387 commit df20429
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/libs/karm-base/async.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "list.h"
#include "rc.h"
#include "res.h"
#include "vec.h"

namespace Karm::Async {

Expand Down Expand Up @@ -224,6 +225,12 @@ struct Cancelation : Meta::Static {
bool canceled() const {
return _c and _c->canceled();
}

Res<> errorIfCanceled() const {
if (canceled())
return Error::interrupted("operation canceled");
return Ok();
}
};

bool _canceled = false;
Expand All @@ -245,6 +252,8 @@ struct Cancelation : Meta::Static {
}
};

using Ct = Cancelation::Token;

// MARK: Promise ---------------------------------------------------------------

template <typename T>
Expand Down

0 comments on commit df20429

Please sign in to comment.