diff --git a/src/CompositeCancellation.php b/src/CompositeCancellation.php index 678a65ea..bdfccdde 100644 --- a/src/CompositeCancellation.php +++ b/src/CompositeCancellation.php @@ -6,6 +6,9 @@ final class CompositeCancellation implements Cancellation { + use ForbidCloning; + use ForbidSerialization; + /** @var array */ private array $cancellations = []; diff --git a/src/DeferredCancellation.php b/src/DeferredCancellation.php index 6915f80a..4d9d56ea 100644 --- a/src/DeferredCancellation.php +++ b/src/DeferredCancellation.php @@ -37,6 +37,9 @@ */ final class DeferredCancellation { + use ForbidCloning; + use ForbidSerialization; + private readonly Internal\Cancellable $source; private readonly Cancellation $cancellation; diff --git a/src/DeferredFuture.php b/src/DeferredFuture.php index 583653e0..38f8ee6b 100644 --- a/src/DeferredFuture.php +++ b/src/DeferredFuture.php @@ -7,6 +7,9 @@ */ final class DeferredFuture { + use ForbidCloning; + use ForbidSerialization; + /** @var Internal\FutureState */ private readonly Internal\FutureState $state; diff --git a/src/ForbidCloning.php b/src/ForbidCloning.php new file mode 100644 index 00000000..92c588f4 --- /dev/null +++ b/src/ForbidCloning.php @@ -0,0 +1,11 @@ + */ diff --git a/src/Internal/WrappedCancellation.php b/src/Internal/WrappedCancellation.php index f6a575e8..bdf1d375 100644 --- a/src/Internal/WrappedCancellation.php +++ b/src/Internal/WrappedCancellation.php @@ -3,12 +3,17 @@ namespace Amp\Internal; use Amp\Cancellation; +use Amp\ForbidCloning; +use Amp\ForbidSerialization; /** * @internal */ final class WrappedCancellation implements Cancellation { + use ForbidCloning; + use ForbidSerialization; + public function __construct( private readonly Cancellation $cancellation ) { diff --git a/src/TimeoutCancellation.php b/src/TimeoutCancellation.php index 2eff9c05..21eb0092 100644 --- a/src/TimeoutCancellation.php +++ b/src/TimeoutCancellation.php @@ -9,6 +9,9 @@ */ final class TimeoutCancellation implements Cancellation { + use ForbidCloning; + use ForbidSerialization; + private readonly string $watcher; private readonly Cancellation $cancellation; diff --git a/test/Cancellation/CompositeCancellationTest.php b/test/Cancellation/CompositeCancellationTest.php index 8688e19f..86bda023 100644 --- a/test/Cancellation/CompositeCancellationTest.php +++ b/test/Cancellation/CompositeCancellationTest.php @@ -34,7 +34,7 @@ public function testBenchmark(): void // Asserts if ($firstMemoryMeasure > 0) { - self::assertEquals($firstMemoryMeasure, \memory_get_usage(true)); + self::assertLessThanOrEqual($firstMemoryMeasure, \memory_get_usage(true)); } } }