diff --git a/src/dorkbox/objectPool/Pool.kt b/src/dorkbox/objectPool/Pool.kt index 570201d..c5e886d 100644 --- a/src/dorkbox/objectPool/Pool.kt +++ b/src/dorkbox/objectPool/Pool.kt @@ -1,5 +1,5 @@ /* - * Copyright 2020 dorkbox, llc + * Copyright 2023 dorkbox, llc * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -45,4 +45,10 @@ interface Pool { * @return a new object instance created by the pool. */ fun newInstance(): T + + + /** + * Clears the underlying queue implementation + */ + fun close() } diff --git a/src/dorkbox/objectPool/SuspendingPool.kt b/src/dorkbox/objectPool/SuspendingPool.kt index 661a3a4..69b18a6 100644 --- a/src/dorkbox/objectPool/SuspendingPool.kt +++ b/src/dorkbox/objectPool/SuspendingPool.kt @@ -1,5 +1,5 @@ /* - * Copyright 2020 dorkbox, llc + * Copyright 2023 dorkbox, llc * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -43,4 +43,9 @@ interface SuspendingPool { * @return a new object instance created by the pool. */ suspend fun newInstance(): T + + /** + * Closes the underlying implementation + */ + fun close() } diff --git a/src/dorkbox/objectPool/blocking/BlockingPool.kt b/src/dorkbox/objectPool/blocking/BlockingPool.kt index eedde68..90b610d 100644 --- a/src/dorkbox/objectPool/blocking/BlockingPool.kt +++ b/src/dorkbox/objectPool/blocking/BlockingPool.kt @@ -1,5 +1,5 @@ /* - * Copyright 2020 dorkbox, llc + * Copyright 2023 dorkbox, llc * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -79,4 +79,11 @@ internal class BlockingPool constructor( override fun newInstance(): T { return poolObject.newInstance() } + + /** + * Clears the underlying queue implementation + */ + override fun close() { + queue.clear() + } } diff --git a/src/dorkbox/objectPool/blocking/BlockingPoolCollection.kt b/src/dorkbox/objectPool/blocking/BlockingPoolCollection.kt index 4159e87..92cd396 100644 --- a/src/dorkbox/objectPool/blocking/BlockingPoolCollection.kt +++ b/src/dorkbox/objectPool/blocking/BlockingPoolCollection.kt @@ -1,5 +1,5 @@ /* - * Copyright 2020 dorkbox, llc + * Copyright 2023 dorkbox, llc * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -73,4 +73,11 @@ internal class BlockingPoolCollection constructor( override fun newInstance(): T { return dummyValue } + + /** + * Clears the underlying queue implementation + */ + override fun close() { + queue.clear() + } } diff --git a/src/dorkbox/objectPool/nonBlocking/NonBlockingPool.kt b/src/dorkbox/objectPool/nonBlocking/NonBlockingPool.kt index 53cb705..623974a 100644 --- a/src/dorkbox/objectPool/nonBlocking/NonBlockingPool.kt +++ b/src/dorkbox/objectPool/nonBlocking/NonBlockingPool.kt @@ -1,5 +1,5 @@ /* - * Copyright 2020 dorkbox, llc + * Copyright 2023 dorkbox, llc * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -67,4 +67,11 @@ internal open class NonBlockingPool( override fun newInstance(): T { return poolObject.newInstance() } + + /** + * Clears the underlying queue implementation + */ + override fun close() { + queue.clear() + } } diff --git a/src/dorkbox/objectPool/nonBlocking/NonBlockingSoftPool.kt b/src/dorkbox/objectPool/nonBlocking/NonBlockingSoftPool.kt index 16a7e5e..99b39c5 100644 --- a/src/dorkbox/objectPool/nonBlocking/NonBlockingSoftPool.kt +++ b/src/dorkbox/objectPool/nonBlocking/NonBlockingSoftPool.kt @@ -1,5 +1,5 @@ /* - * Copyright 2020 dorkbox, llc + * Copyright 2023 dorkbox, llc * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -77,4 +77,11 @@ internal class NonBlockingSoftPool( override fun newInstance(): T { return poolObject.newInstance() } + + /** + * Clears the underlying queue implementation + */ + override fun close() { + queue.clear() + } } diff --git a/src/dorkbox/objectPool/suspending/ChannelQueue.kt b/src/dorkbox/objectPool/suspending/ChannelQueue.kt index 8e40b5d..63996f1 100644 --- a/src/dorkbox/objectPool/suspending/ChannelQueue.kt +++ b/src/dorkbox/objectPool/suspending/ChannelQueue.kt @@ -1,5 +1,5 @@ /* - * Copyright 2022 dorkbox, llc + * Copyright 2023 dorkbox, llc * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -55,4 +55,8 @@ class ChannelQueue(size: Int): SuspendingQueue { override suspend fun take(): E { return channel.receive() } + + override fun close() { + channel.close() + } } diff --git a/src/dorkbox/objectPool/suspending/SuspendingPool.kt b/src/dorkbox/objectPool/suspending/SuspendingPool.kt index 6c9ecad..7ce356e 100644 --- a/src/dorkbox/objectPool/suspending/SuspendingPool.kt +++ b/src/dorkbox/objectPool/suspending/SuspendingPool.kt @@ -1,5 +1,5 @@ /* - * Copyright 2020 dorkbox, llc + * Copyright 2023 dorkbox, llc * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -82,4 +82,11 @@ internal class SuspendingPool constructor( override suspend fun newInstance(): T { return poolObject.newInstance() } + + /** + * Closes the supporting queue implementation + */ + override fun close() { + queue.close() + } } diff --git a/src/dorkbox/objectPool/suspending/SuspendingPoolCollection.kt b/src/dorkbox/objectPool/suspending/SuspendingPoolCollection.kt index 1044a34..7e04d74 100644 --- a/src/dorkbox/objectPool/suspending/SuspendingPoolCollection.kt +++ b/src/dorkbox/objectPool/suspending/SuspendingPoolCollection.kt @@ -1,5 +1,5 @@ /* - * Copyright 2020 dorkbox, llc + * Copyright 2023 dorkbox, llc * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -74,4 +74,11 @@ internal class SuspendingPoolCollection constructor( override suspend fun newInstance(): T { return dummyValue } + + /** + * Closes the underlying queue implementation + */ + override fun close() { + queue.close() + } } diff --git a/src/dorkbox/objectPool/suspending/SuspendingQueue.kt b/src/dorkbox/objectPool/suspending/SuspendingQueue.kt index b541ba3..3e6fe3c 100644 --- a/src/dorkbox/objectPool/suspending/SuspendingQueue.kt +++ b/src/dorkbox/objectPool/suspending/SuspendingQueue.kt @@ -1,5 +1,5 @@ /* - * Copyright 2022 dorkbox, llc + * Copyright 2023 dorkbox, llc * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -89,4 +89,9 @@ interface SuspendingQueue { * @return the head of this queue, or {@code null} if this queue is empty */ fun poll(): E? + + /** + * Closes the underlying implementation + */ + fun close() }