Skip to content

MainScheduler documentation omits an important detail #2704

@isaac-weisberg

Description

@isaac-weisberg

Specifically this line.

While it is true in a basic sense, there is additional logic, that if some other thread schedules a block via this scheduler, all subsequent schedules that happen even from the main thread will lead to the block being queued behind via DispatchQueue.async in order to preserve temporal serialization of events.

And because usually people use MainScheduler.instance, which is process-wise singleton, this can create surprising results where absolutely unrelated parts of the system can schedule blocks from wrong thread, preventing other parts from running their code on main thread synchronously, and accidentally causing unrelated systems to be temporally serialized where it's in fact not necessary.

We have a code that is performing UI sensitive transition, so everything should be executed essentially synchronously, but absolutely unrelated components caused our blocks to be always rescheduled, breaking the transitions. We are going to solve it by not using MainScheduler.instance and instead using MainScheduler()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions