I have created a service for a storage set with a UUID and want to get() the value in the console, but it just crashes on every single attempt in Chrome and an emulator. Is something wrong with my code?
By the way, set()
works but not get()
constructor(public storage: Storage) { }
public async setParam(name: string, value: any) {
return await this.storage.set(name, value);
}
public getParam(name: string): Promise<any> {
return this.storage.get(name).then((val) => { console.log(val); });
}
}
Also depends on your calling code
But for sure both functions seem pointless to me
The getParam is returning nothing of use for the caller (void probably)
And the setparam neither returns something interesting as the await resolves the function which returns nothing of use )neither error). Although it does probably set something in memory
So hence Inexpect the caller does something Illegal with void or undefined which generally is a bad idea
1 Like
There’s another potential problem. What I do here is:
async get<T>(key: string): Promise<T> {
await this.lf.ready();
return this.lf.get(key);
}
Trying to interact with Storage
before it’s ready results in two words that should turn the blood cold of anybody old enough to remember comp.lang.c on Usenet: “undefined behavior”.