Libraryless. Click here for Pure Java version (9091L/50K).
1 | sclass CloseablesHolder > Meta is AutoCloseable, IResourceHolder { |
2 | new LinkedHashSet<AutoCloseable> closeables; |
3 | WeakRef<Thread> createdInThread = weakRef(currentThread()); |
4 | |
5 | public synchronized <A extends AutoCloseable> void addAll(Iterable<A> l) { |
6 | fOr (var a : l) add(a); |
7 | } |
8 | |
9 | public synchronized <A extends AutoCloseable> A add(A a) { |
10 | if (a != null) |
11 | closeables.add(a); |
12 | ret a; |
13 | } |
14 | |
15 | // remove from list, don't close |
16 | synchronized <A extends AutoCloseable> A remove aka takeOut(A a) { |
17 | closeables.remove(a); |
18 | ret a; |
19 | } |
20 | |
21 | // close and remove |
22 | synchronized <A extends AutoCloseable> A close(A a) { |
23 | if (a == null) ret a; |
24 | closeables.remove(a); |
25 | main close(a); |
26 | ret a; |
27 | } |
28 | |
29 | close { |
30 | for (AutoCloseable c : reversed(takeAll())) |
31 | main close(c); |
32 | } |
33 | |
34 | public synchronized void forget aka clear() { |
35 | closeables.clear(); |
36 | } |
37 | |
38 | public synchronized Cl<AutoCloseable> takeAll() { |
39 | ret cloneAndClear(closeables); |
40 | } |
41 | } |
download show line numbers debug dex old transpilations
Travelled to 8 computer(s): bhatertpkbcr, ekrmjmnbrukm, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv
No comments. add comment
Snippet ID: | #1029397 |
Snippet name: | CloseablesHolder - temporarily hold resources |
Eternal ID of this version: | #1029397/18 |
Text MD5: | 10a3c6ae9d8cfe46bf97d5e2c480302f |
Transpilation MD5: | 7da750866ee3fc42e0db0605d4c56081 |
Author: | stefan |
Category: | javax |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2022-05-08 23:16:57 |
Source code size: | 1026 bytes / 41 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 351 / 720 |
Version history: | 17 change(s) |
Referenced in: | [show references] |