It would be nice to have a dedicated method in the Zone trait to obtain more information about its current status. For instance it could be isClosed() to be consistent with the close() method defined in the the ZoneImpl private class.
Possible use cases:
Another extension I've been thinking of in the same space is to allow open-ended zones. For example:
def m1 = {
val z = Zone.open
...
}
def m2 = {
...
z.close
}
Current implementations of zones makes them impossible to use when the closing point of the zone is not in the same scope (which can happen in async programming for example).
Naturally it would be good to have some way to know if zone is open/closed in this kind of scenario.
I am recently interested in scala-native and feel that this is good for the first issue. Can I implement this feature? I am thinking of adding the below three methods to Zone trait and the companion object as suggested.
trait Zone {
/** Allocates memory of given size. */
def alloc(size: CSize): Ptr[Byte]
def close(): Unit // added
def isClosed: Boolean // added
}
object Zone {
...
def open(): Zone = ... // added
}
@tiqwab Go for it.
I am also wondering if Zones can be nested and if there are any implications that need to be considered?
@ekrich Zones can be nested, there are no implications.