.catch
возвращает обещание, но вам нужно что-то вернуть в своем блоке catch
. Вам нужно будет вернуть строку или ноль.
export async function getType(
serviceID: string,
vendor: string,
{ inventory = defaultKeyinventory } = {}
): Promise<string | null>{
const item= inventory !.getItem(serviceID, vendor)
.catch(() => return null);
return item;
}
Я не уверен, почему второй подход Вы связали с запусками другой поток; я полагаю, что аудио будет играться в его собственном потоке так или иначе. Состоит в том проблема, что Ваше приложение заканчивается, прежде чем клип закончил играть?
import javax.sound.sampled.*;
import java.io.File;
import java.io.IOException;
import javax.sound.sampled.LineEvent.Type;
private static void playClip(File clipFile) throws IOException,
UnsupportedAudioFileException, LineUnavailableException, InterruptedException {
class AudioListener implements LineListener {
private boolean done = false;
@Override public synchronized void update(LineEvent event) {
Type eventType = event.getType();
if (eventType == Type.STOP || eventType == Type.CLOSE) {
done = true;
notifyAll();
}
}
public synchronized void waitUntilDone() throws InterruptedException {
while (!done) { wait(); }
}
}
AudioListener listener = new AudioListener();
AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(clipFile);
try {
Clip clip = AudioSystem.getClip();
clip.addLineListener(listener);
clip.open(audioInputStream);
try {
clip.start();
listener.waitUntilDone();
} finally {
clip.close();
}
} finally {
audioInputStream.close();
}
}