@u4/adbkit
Version:
A Typescript client for the Android Debug Bridge.
39 lines • 1 kB
JavaScript
export default class ServiceMap {
constructor() {
this.remotes = Object.create(null);
this.count = 0;
}
end() {
const ref = this.remotes;
for (const remoteId in ref) {
const remote = ref[remoteId];
remote.end();
}
this.remotes = Object.create(null);
this.count = 0;
}
insert(remoteId, socket) {
if (this.remotes[remoteId]) {
throw new Error(`Remote ID ${remoteId} is already being used`);
}
else {
this.count += 1;
return (this.remotes[remoteId] = socket);
}
}
get(remoteId) {
return this.remotes[remoteId] || null;
}
remove(remoteId) {
let remote;
if ((remote = this.remotes[remoteId])) {
delete this.remotes[remoteId];
this.count -= 1;
return remote;
}
else {
return null;
}
}
}
//# sourceMappingURL=servicemap.js.map