Added support to clear/close the underlying queue implementation

master
Robinson 2023-06-07 22:34:35 +02:00
parent 7d6424bc11
commit 8cfb08d63d
No known key found for this signature in database
GPG Key ID: 8E7DB78588BD6F5C
10 changed files with 72 additions and 10 deletions

View File

@ -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<T> {
* @return a new object instance created by the pool.
*/
fun newInstance(): T
/**
* Clears the underlying queue implementation
*/
fun close()
}

View File

@ -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<T> {
* @return a new object instance created by the pool.
*/
suspend fun newInstance(): T
/**
* Closes the underlying implementation
*/
fun close()
}

View File

@ -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<T> constructor(
override fun newInstance(): T {
return poolObject.newInstance()
}
/**
* Clears the underlying queue implementation
*/
override fun close() {
queue.clear()
}
}

View File

@ -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<T> constructor(
override fun newInstance(): T {
return dummyValue
}
/**
* Clears the underlying queue implementation
*/
override fun close() {
queue.clear()
}
}

View File

@ -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<T>(
override fun newInstance(): T {
return poolObject.newInstance()
}
/**
* Clears the underlying queue implementation
*/
override fun close() {
queue.clear()
}
}

View File

@ -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<T>(
override fun newInstance(): T {
return poolObject.newInstance()
}
/**
* Clears the underlying queue implementation
*/
override fun close() {
queue.clear()
}
}

View File

@ -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<E>(size: Int): SuspendingQueue<E> {
override suspend fun take(): E {
return channel.receive()
}
override fun close() {
channel.close()
}
}

View File

@ -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<T> constructor(
override suspend fun newInstance(): T {
return poolObject.newInstance()
}
/**
* Closes the supporting queue implementation
*/
override fun close() {
queue.close()
}
}

View File

@ -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<T> constructor(
override suspend fun newInstance(): T {
return dummyValue
}
/**
* Closes the underlying queue implementation
*/
override fun close() {
queue.close()
}
}

View File

@ -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<E> {
* @return the head of this queue, or {@code null} if this queue is empty
*/
fun poll(): E?
/**
* Closes the underlying implementation
*/
fun close()
}