Last active
December 10, 2019 13:30
-
-
Save andreastt/0d081f4767d7d8ffdaea8c08386bfc9c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"use strict"; | |
var EXPORTED_SYMBOLS = ["StreamHandleCache"]; | |
var singleton; | |
class StreamHandleCache extends Map { | |
constructor() { | |
super(); | |
Services.obs.addObserver(this, "xpcom-will-shutdown"); | |
} | |
destructor() { | |
for (const [handle, stream] of this.entries()) { | |
// do whatever is necessary to destroy stream | |
} | |
} | |
observe(subject, topic, data) { | |
this.destructor(); | |
} | |
static get() { | |
if (!singleton) { | |
singleton = new StreamHandleCache(); | |
} | |
return singleton; | |
} | |
} | |
… | |
// In bc test: | |
const { StreamHandleCache } = ChromeUtils.import(…); | |
const cache = StreamHandleCache.get(); | |
add_task(function() { | |
cache.add(handle, new Stream()); | |
cache.destructor(); | |
is(cache.size, 0); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment