# observeOn

**指定 `Observable` 在那个 `Scheduler` 发出通知**

![](/files/-MWlwPYzNkCV3qsC08QU)

**ReactiveX** 使用 [Scheduler](/rxswift/rxswift_core/schedulers.md) 来让 `Observable` 支持多线程。你可以使用 **observeOn** 操作符，来指示 `Observable` 在哪个 [Scheduler](/rxswift/rxswift_core/schedulers.md) 发出通知。

![](/files/-MWlwPZ-T19dackDj_gZ)

注意⚠️：一旦产生了 `onError` 事件， **observeOn** 操作符将立即转发。他不会等待 `onError` 之前的事件全部被收到。这意味着 `onError` 事件可能会跳过一些元素提前发送出去，如上图所示。

![](/files/-MWlwPZ09uFkCjzY_0F2)

[subscribeOn](/rxswift/decision_tree/subscribeon.md) 操作符非常相似。它指示 `Observable` 在哪个 [Scheduler](/rxswift/rxswift_core/schedulers.md) 发出执行。

默认情况下，`Observable` 创建，应用操作符以及发出通知都会在 `Subscribe` 方法调用的 [Scheduler](/rxswift/rxswift_core/schedulers.md) 执行。[subscribeOn](/rxswift/decision_tree/subscribeon.md) 操作符将改变这种行为，它会指定一个不同的 [Scheduler](/rxswift/rxswift_core/schedulers.md) 来让 `Observable` **执行，observeOn** 操作符将指定一个不同的 [Scheduler](/rxswift/rxswift_core/schedulers.md) 来让 `Observable` 通知观察者。

如上图所示，[subscribeOn](/rxswift/decision_tree/subscribeon.md) 操作符指定 `Observable` 在那个 [Scheduler](/rxswift/rxswift_core/schedulers.md) 开始执行，无论它处于链的那个位置。 另一方面 **observeOn** 将决定后面的方法在哪个 [Scheduler](/rxswift/rxswift_core/schedulers.md) 运行。因此，你可能会多次调用 **observeOn** 来决定某些操作符在哪个线程运行。


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://3440217568.gitbook.io/rxswift/decision_tree/observeon.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
