A Command-Line Tool with CoreHID & Async / Await -- how to enumerate devices up-front / once?

I'm probably missing something really basic here:

I'm using CoreHID to interact with HID devices, and I want to have a command-line tool that interacts with some particular devices.

In order to enumerate the devices of interest, I need to use monitorNotifications(matchingCriteria:) | Apple Developer Documentation and that works as expected, but doesn't really seem appropriate for a command-line tool that essentially acts on the system state at a given time and then exits, but doesn't keep running continously.

Let's say I would like my tool to interact with a keyboard, and then exit, how do I do that? I do not know in advance how many (matching) devices there might be, since all I get is an async stream. There might be no matching devices and I wait forever? I also don't want to just start on the first (or every) match, since there might be more than one.

Waiting for some semi-empiric amount of time to then cancel / exit seems like the wrong way to go about this, no?

1 Like

As this is specific to Apple Core HID framework, let’s focus this discussion on your DevForums thread.

Share and Enjoy

Quinn “The Eskimo!” @ DTS @ Apple

Thanks, Quinn.

(Sometimes I'm not quite sure where things belong, whether it's the framework, or me holding AsyncThrowingSequence incorrectly, but for now I didn't find anything on the Swift concurrency-side to help me. :slight_smile: )