Skip to content

Newb thread question #80

@jeff-h

Description

@jeff-h

I understand the dispatchOnQueue method allows a subscriber to specify the thread on which to run its callback code.

However, I need to fire events from code which is running on a background thread. As it happens, all subscribers to these events are in the main thread. It feels like using dispatchOnQueue in this case would require the subscribers to know about the origin of the event, leading to tightly-coupled code.

So I assume the obvious solution is to fire the events on the main thread in the first place:

// Send a signal on the main thread.
DispatchQueue.main.async {
    self.onRawStderrorReceived.fire(stringData)
}

Does this approach sound correct? The reason I am asking is that I keep getting Thread 1: EXC_BAD_ACCESS (code=1, address=0xfffffffffffffff0) errors thrown at that point (Xcode actually highlights the comment, oddly).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions