Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
nimau committed Oct 24, 2023
1 parent 1ee80e1 commit 95b6d33
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions ElementX/Sources/Services/Audio/Recorder/AudioRecorder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,21 +50,14 @@ class AudioRecorder: NSObject, AudioRecorderProtocol, AVAudioRecorderDelegate {
guard await requestRecordPermission() else {
return .failure(.recordPermissionNotGranted)
}
return await withCheckedContinuation { continuation in
startRecording(with: recordID) { [weak self] result in
guard let self else {
continuation.resume(returning: .failure(.recordingCancelled))
return
}
switch result {
case .success:
actionsSubject.send(.didStartRecording)
case .failure(let error):
actionsSubject.send(.didFailWithError(error: error))
}
continuation.resume(returning: result)
}
let result = await startRecording(with: recordID)
switch result {
case .success:
actionsSubject.send(.didStartRecording)
case .failure(let error):
actionsSubject.send(.didFailWithError(error: error))
}
return result
}

func stopRecording() async {
Expand Down Expand Up @@ -127,6 +120,14 @@ class AudioRecorder: NSObject, AudioRecorderProtocol, AVAudioRecorderDelegate {

// MARK: - Private

private func startRecording(with recordID: AudioRecordingIdentifier) async -> Result<Void, AudioRecorderError> {
await withCheckedContinuation { continuation in
startRecording(with: recordID) { result in
continuation.resume(returning: result)
}
}
}

private func startRecording(with recordID: AudioRecordingIdentifier, completion: @escaping (Result<Void, AudioRecorderError>) -> Void) {
dispatchQueue.async { [weak self] in
guard let self, !self.stopped else {
Expand Down

0 comments on commit 95b6d33

Please sign in to comment.