Debian Codegraph @

lib/3rdParty/composer/aws/aws-crt-php/src/AWS/CRT/IO/EventLoopGroup.php

raw symbols SCIP
1 <?php
2 /**
3 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
4 * SPDX-License-Identifier: Apache-2.0.
5 */
6 namespace AWS\CRT\IO;
7
8 use AWS\CRT\NativeResource as NativeResource;
9 use AWS\CRT\Options as Options;
10
11 /**
12 * Represents 1 or more event loops (1 per thread) for doing I/O and background tasks.
13 * Typically, every application has one EventLoopGroup.
14 *
15 * @param array options:
16 * - int num_threads - Number of worker threads in the EventLoopGroup. Defaults to 0/1 per logical core.
17 */
18 final class EventLoopGroup extends NativeResource {
19
20 static function defaults() {
21 return [
22 'max_threads' => 0,
23 ];
24 }
25
26 function __construct(array $options = []) {
27 parent::__construct();
28 $options = new Options($options, self::defaults());
29 $elg_options = self::$crt->event_loop_group_options_new();
30 self::$crt->event_loop_group_options_set_max_threads($elg_options, $options->getInt('max_threads'));
31 $this->acquire(self::$crt->event_loop_group_new($elg_options));
32 self::$crt->event_loop_group_options_release($elg_options);
33 }
34
35 function __destruct() {
36 self::$crt->event_loop_group_release($this->release());
37 parent::__destruct();
38 }
39 }