---
description: 命名空间和模块：tencent.cloud.core.waitable
---

# Waitable 类

## 简要

代表一个可等待操作对象的基本类型。借助可等待对象，开发者可以以同步或异步面向对象编程的方式等待一个异步操作真正地完成，例如同步等待一个或多个无服务器云函数资源创建完成。

```python
class Waitable
```

## 属性

可等待操作对象类型的实例包含可公开访问的属性如下：

| 属性     | 类型     | 只读 | 描述                                                                                                                                                                           |
| ------ | ------ | -- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| status | int    | 是  | <p>指示可等待操作对象的状态。<br>与该属性的值相关的是 <a href="https://smallso.gitbook.io/tencent-cloud-sdk/python-docs/other-products/data-types/waitable-status-enum">WaitableStatus</a> 枚举器。</p> |
| result | object | 是  | <p>指示可等待操作对象对应的可等待操作的返回值。</p><p>如果可等待操作没有返回值，该属性的值默认为 <code>None</code>。</p>                                                                                                 |

{% content-ref url="../data-types/waitable-status-enum" %}
[waitable-status-enum](../data-types/waitable-status-enum)
{% endcontent-ref %}

## 示例

在下文中我们将通过一段 Python 代码片段向您演示如何使用可等待操作对象：

```python
from tencent.cloud.core import errors
from tencent.cloud.core import waitable
from tencent.cloud.serverless import functions

def main():
    client: functions.Client = functions.fetch_client()

    create_operation: waitable.Waitable = client.create_layer(
        region_id = 'ap-shanghai',
        layer_name = 'default',
        layer_description = 'default layer',
        layer_content = functions.LayerContent().use_local_zip_archive(
            local_file_path = './layer.zip'
        ),
        layer_runtimes = [
            functions.FunctionRuntime.Python
        ],
        layer_license = 'default license'
    )

    try:
        layer_version: int = create_operation.wait_for_done(
            max_wait_seconds = 15
        )
    except TimeoutError:
        print('error: max time limit exceeded when creating layer resource')
        return
    
    print('info: layer version = {LAYER_VERSION}'.format(
        LAYER_VERSION = layer_version
    ))

if __name__ == '__main__':
    main()
```

## 适用于

#### Tencent Cloud SDK for Python

产品软件包：tencent-cloud-sdk-core >= 0.1.5
