• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

hyperledger / identus-edge-agent-sdk-swift / 10452854535

19 Aug 2024 11:56AM UTC coverage: 43.49% (-0.09%) from 43.578%
10452854535

Pull #152

github

web-flow
Merge 57ebdee45 into 3ec399adc
Pull Request #152: test: add backup and revocation message e2e scenarios

2 of 49 new or added lines in 4 files covered. (4.08%)

5101 of 11729 relevant lines covered (43.49%)

99.34 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/EdgeAgentSDK/EdgeAgent/Sources/EdgeAgent+MessageEvents.swift
1
import Combine
2
import Domain
3
import Foundation
4

5
// MARK: Messaging events funcionalities
6
public extension EdgeAgent {
7
    /// Start fetching the messages from the mediator
8
    func startFetchingMessages(timeBetweenRequests: Int = 5) {
×
9
        let timeInterval = max(timeBetweenRequests, 5)
×
10
        guard
×
11
            let connectionManager,
×
12
            messagesStreamTask == nil
×
13
        else { return }
×
14

×
15
        logger.info(message: "Start streaming new unread messages")
×
16
        let manager = connectionManager
×
17
        messagesStreamTask = Task {
×
18
            // Keep trying to fetch messages until the task is cancelled
×
19
            while true {
×
20
                do {
×
21
                     logger.debug(message: "Fetching new batch of 10 unread messages")
×
22
                    // Wait for new messages to arrive
×
23
                     _ = try await manager.awaitMessages()
×
24
                } catch {
×
25
                    // Handle errors that occur during the message fetching process
×
26
                    logger.error(error: error)
×
27
                }
×
28
                sleep(UInt32(timeInterval))
×
NEW
29
                
×
NEW
30
                if (messagesStreamTask?.isCancelled == true) {
×
NEW
31
                    break
×
NEW
32
                }
×
33
            }
×
34
        }
×
35
    }
×
36

37
    /// Stop fetching messages
38
    func stopFetchingMessages() {
×
39
        logger.info(message: "Stop streaming new unread messages")
×
40
        messagesStreamTask?.cancel()
×
41
    }
×
42

43
    /// Handles the messages events and return a publisher of the messages
44
    /// - Returns: A publisher of the messages that emits an event with a `Message` and completed or failed with an `Error`
45
    func handleMessagesEvents() -> AnyPublisher<Message, Error> {
×
46
        pluto.getAllMessages()
×
47
            .flatMap { $0.publisher }
×
48
            .eraseToAnyPublisher()
×
49
    }
×
50

51
    /// Sends a DIDComm message through HTTP using mercury and returns a message if this is returned immediately by the REST endpoint.
52
    ///
53
    /// - Parameters:
54
    ///   - message: The message to be sent.
55
    /// - Returns: The sent message if successful, otherwise `nil`.
56
    /// - Throws: An error if the sending fails.
57
    func sendMessage(message: Message) async throws -> Message? {
×
58
        return try await connectionManager?.sendMessage(message)
×
59
    }
×
60

61
    /// Handles the received messages events and return a publisher of the messages
62
    /// - Returns: A publisher of the messages that emits an event with a `Message` and completed or failed with an `Error`
63
    func handleReceivedMessagesEvents() -> AnyPublisher<Message, Error> {
×
64
        pluto.getAllMessagesReceived()
×
65
            .flatMap { $0.publisher }
×
66
            .eraseToAnyPublisher()
×
67
    }
×
68
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc