Inotify event stream is dependent on system usage. Increasing the timeouts helps not having to repeat the integration tests.
26 lines
571 B
Swift
26 lines
571 B
Swift
import Inotify
|
|
|
|
func getEventsForTrigger(
|
|
in dir: String,
|
|
mask: InotifyEventMask,
|
|
trigger: @escaping (String) async throws -> Void
|
|
) async throws -> [InotifyEvent] {
|
|
let watcher = try Inotify()
|
|
try await watcher.addWatch(path: dir, mask: mask)
|
|
|
|
let eventTask = Task {
|
|
var events: [InotifyEvent] = []
|
|
for await event in await watcher.events {
|
|
events.append(event)
|
|
}
|
|
return events
|
|
}
|
|
|
|
try await Task.sleep(for: .milliseconds(100))
|
|
try await trigger(dir)
|
|
try await Task.sleep(for: .milliseconds(500))
|
|
|
|
eventTask.cancel()
|
|
return await eventTask.value
|
|
}
|