My Sleep/Delay function is giving me trouble.
I attempted to utilize the delay function from 'rxjs/operators', but it seems to be failing.
Below is my code snippet:
sentence: string = "Hallo"
wordToMorse(sentence: any) {
for (var char of sentence) {
if (char != " ") {
this.vibrateWord(char);
this.pause(1000);
} else {
this.pause(1000);
}
}
}
vibrateWord(character: any) {
if (character == "H") {
this.vibrator.vibrate(500);
} else if (character == "a") {
this.vibrator.vibrate(1000);
} else if (character == "l") {
this.vibrator.vibrate(500);
} else if (character == "o") {
this.vibrator.vibrate(2000);
}
}
async pause(ms: number) {
await new Promise(resolve => setTimeout(()=>resolve(), ms)).then(()=>console.log("fired"));
}
I am anticipating that there should be a 1-second delay after each vibration for a letter in the sentence.