| 670 | } |
| 671 | |
| 672 | Result AwaitTask::cancel(AwaitEventLoop& await) |
| 673 | { |
| 674 | if (not handle) |
| 675 | { |
| 676 | return Result::Error("AwaitTask is invalid"); |
| 677 | } |
| 678 | Promise& promise = handle.promise(); |
| 679 | if (promise.completed) |
| 680 | { |
| 681 | return Result(true); |
| 682 | } |
| 683 | if (promise.eventLoop != nullptr and promise.eventLoop != &await) |
| 684 | { |
| 685 | return AwaitWrongEventLoopResult(); |
| 686 | } |
| 687 | if (not promise.started) |
| 688 | { |
| 689 | return Result::Error("AwaitTask is not started"); |
| 690 | } |
| 691 | if (promise.cancellationRequested) |
| 692 | { |
| 693 | return Result(true); |
| 694 | } |
| 695 | if (promise.cancellation.cancel == nullptr) |
| 696 | { |
| 697 | return Result::Error("AwaitTask cannot be cancelled right now"); |
| 698 | } |
| 699 | promise.cancellationRequested = true; |
| 700 | return promise.cancellation.cancel(promise.cancellation.object, await); |
| 701 | } |
| 702 | |
| 703 | bool AwaitTask::await_ready() const { return not isActive(); } |
| 704 | |