diff --git a/README.md b/README.md index 0c363f2..b47b81f 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,10 @@ -# nodejs-project-template +# CasinoJs -nodejs-project-template +CasinoJs ## Table of Contents -- [nodejs-project-template](#nodejs-project-template) +- [CasinoJs](#casinojs) - [Table of Contents](#table-of-contents) - [Feedback and Suggestions](#feedback-and-suggestions) diff --git a/docs/PROJECT_STRUCTURE.md b/docs/PROJECT_STRUCTURE.md index 3e81b33..b84940c 100644 --- a/docs/PROJECT_STRUCTURE.md +++ b/docs/PROJECT_STRUCTURE.md @@ -1,77 +1,313 @@ # Project Structure -This document provides a comprehensive overview of the directory structure for the `pokerjs` repository. It outlines the purpose and organization of each directory and file, ensuring a clear understanding of where to find various components of the project. +## Introduction + +This document provides a comprehensive overview of the directory structure for the `CasinoJs` repository. It outlines the purpose and organization of each directory and file, ensuring a clear understanding of where to find various components of the project. ## Table of Contents - [Project Structure](#project-structure) + - [Introduction](#introduction) - [Table of Contents](#table-of-contents) - - [Root Directory Layout](#root-directory-layout) + - [./ Directory Layout](#-directory-layout) + - [./.envs Directory Layout](#envs-directory-layout) + - [./.github Directory Layout](#github-directory-layout) + - [./coverage Directory Layout](#coverage-directory-layout) + - [./dist Directory Layout](#dist-directory-layout) + - [./docs Directory Layout](#docs-directory-layout) + - [./src Directory Layout](#src-directory-layout) + - [./src/enums Directory Layout](#srcenums-directory-layout) + - [./src/events Directory Layout](#srcevents-directory-layout) + - [./src/interfaces Directory Layout](#srcinterfaces-directory-layout) + - [./src/models Directory Layout](#srcmodels-directory-layout) + - [./tests Directory Layout](#tests-directory-layout) + - [./tests/enums Directory Layout](#testsenums-directory-layout) + - [./tests/events Directory Layout](#testsevents-directory-layout) + - [./tests/interfaces Directory Layout](#testsinterfaces-directory-layout) + - [./tests/models Directory Layout](#testsmodels-directory-layout) -## Root Directory Layout +## ./ Directory Layout ```bash -├── /.envs # Environment configuration files for different environments -│ ├── .env.development.local.example # Example environment configuration file for development environment -│ ├── .env.example # Example environment configuration file for local development -│ ├── .env.local.example # Example environment configuration file for local overrides -│ ├── .env.production.local.example # Example environment configuration file for production environment -│ └── .env.test.local.example # Example environment configuration file for testing environment -│ -├── /.github # GitHub-related configuration files -│ ├── /COMMIT_TEMPLATE # Commit message templates for standardized commit messages -│ │ └── commit_template.md # Template for commit messages to maintain consistency -│ │ -│ ├── /ISSUE_TEMPLATE # Templates for creating issues -│ │ ├── bug_report_form.yml # YAML file defining the form for reporting bugs -│ │ ├── bug_report_template.md # Markdown template for bug reports -│ │ └── feature_request_template.md # Markdown template for feature requests -│ │ -│ └── /PULL_REQUEST_TEMPLATE # Templates for pull requests -│ └── pull_request_template.md # Markdown template for pull requests to ensure all necessary information is provided -│ -├── /docs # Documentation and guides related to the project -│ ├── /site # Generated documentation from Typedoc -│ │ ├── assets/ # Assets used in the documentation site -│ │ ├── classes/ # Generated class documentation -│ │ ├── enums/ # Generated enums documentation -│ │ ├── media/ # Media files for the documentation -│ │ ├── modules/ # Generated modules documentation -│ │ ├── .nojekyll # File to disable GitHub Pages Jekyll processing -│ │ ├── index.html # Documentation index page -│ │ └── modules.html # List of modules in the documentation -│ │ -│ ├── CHANGELOG.md # Record of changes and updates made to the project over time -│ ├── CONTRIBUTING.md # Guidelines and instructions for contributing to the project -│ ├── DEVELOPMENT_GUIDE.md # Step-by-step guide for developers to set up and work on the project -│ ├── DOCS.md # General documentation, including API details, usage instructions, and best practices -│ └── PROJECT_STRUCTURE.md # Detailed explanation of the project's directory structure and file purposes +├── /.envs # Environment configuration files for different environments +├── /.github # GitHub configuration files for commits, issues, and PR templates +├── /coverage # Test coverage reports generated after running the test suite +├── /dist # Compiled output files generated by TypeScript for distribution +├── /docs # Documentation and guides for the project +├── /src # Source code for the CasinoJs library +├── /tests # Unit tests for verifying poker models and project functionality +├── .gitignore # Specifies files and directories ignored by Git +├── jest.config.js # Configuration file for Jest, defining paths and options for testing +├── LICENSE # License file outlining the terms of distribution +├── package-lock.json # Dependency tree capture for consistent installations +├── package.json # Project metadata, including dependencies and scripts +├── README.md # Overview of the project, with setup and usage information +├── tsconfig.cjs.json # TypeScript configuration for CommonJS builds +├── tsconfig.esm.json # TypeScript configuration for ESModule builds +└── tsconfig.json # Main TypeScript configuration for overall compiler options +``` + +## ./.envs Directory Layout + +```bash +├── .env.development.local.example # Development environment configuration file example +├── .env.example # General local development configuration file example +├── .env.local.example # Local overrides configuration file example (machine-specific) +├── .env.production.local.example # Production deployment configuration file example +└── .env.test.local.example # Test environment configuration file example +``` + +## ./.github Directory Layout + +```bash +├── /COMMIT_TEMPLATE # Directory holding templates for commit messages +│ └── commit_template.md # Markdown template for consistent commit messages, ensuring detailed descriptions with title, summary, type, and other sections +├── /ISSUE_TEMPLATE # Directory containing templates for creating GitHub issues +│ ├── bug_report_form.yml # YAML configuration for submitting bug reports via GitHub’s form-based interface +│ ├── bug_report_template.md # Markdown template for reporting bugs, with fields for issue description, steps to reproduce, expected vs. actual behavior, etc. +│ └── feature_request_template.md # Markdown template for requesting new features or improvements, outlining the feature's purpose and desired functionality +└── /PULL_REQUEST_TEMPLATE # Directory containing templates for submitting pull requests + └── pull_request_template.md # Markdown template with structured fields for pull request descriptions, including changes summary, purpose, testing notes, and checklist +``` + +## ./coverage Directory Layout + +```bash +├── /Icov-report # HTML-based coverage reports directory +│ ├── /enums # Coverage for enums in the project +│ ├── /models # Coverage for models in the project +│ ├── base.css # CSS styling for coverage reports +│ ├── block-navigation.js # JavaScript for navigation within the report +│ ├── favicon.png # Favicon for the report HTML pages +│ ├── index.html # Main entry point for the coverage report +│ ├── prettify.css # CSS for code snippet formatting +│ ├── prettify.js # JavaScript for syntax highlighting +│ ├── sort-arrow-sprite.png # Arrow sprite used in report navigation +│ └── sorter.js # JavaScript for sorting report data │ -├── /src # Source code for the pokerjs library -│ ├── /interfaces # TypeScript interfaces for the poker models -│ │ ├── /rank # Rank interface for card ranks -│ │ │ └── index.ts # Exports for rank-related types -│ │ ├── /suit # Suit interface for card suits -│ │ │ └── index.ts # Exports for suit-related types -│ │ └── index.ts # Main export for all interfaces -│ │ -│ ├── /models # Core poker models and logic -│ │ ├── /card # Card model representing a playing card -│ │ │ └── index.ts # Card model implementation -│ │ ├── /deck # Deck model representing a deck of playing cards -│ │ │ └── index.ts # Deck model implementation -│ │ └── index.ts # Exports for all models -│ │ -├── /tests # Unit tests for poker logic -│ ├── deck.test.ts # Unit tests for the Deck model -│ ├── player.test.ts # Unit tests for the Player model +├── clover.xml # XML format report for coverage analysis tools +├── coverage-final.json # JSON summary of coverage results +└── lcov.info # LCOV format coverage report for tools like Coveralls +``` + +## ./dist Directory Layout + +```bash +├── /cjs # CommonJS entry point after TypeScript compilation +│ ├── enums/ # Compiled enums for CommonJS +│ ├── interfaces/ # Compiled interfaces for CommonJS +│ ├── models/ # Compiled models for CommonJS +│ ├── index.d.ts # TypeScript declaration for CommonJS entry point +│ ├── index.js # CommonJS entry point after compilation +│ └── index.js.map # Source map for CommonJS entry point │ -├── /dist # Compiled output files generated by TypeScript +└── /esm # ESModule entry point after TypeScript compilation + ├── enums/ # Compiled enums for ESModule + ├── interfaces/ # Compiled interfaces for ESModule + ├── models/ # Compiled models for ESModule + ├── index.d.ts # TypeScript declaration for ESModule entry point + ├── index.js # ESModule entry point after compilation + └── index.js.map # Source map for ESModule entry point +``` + +## ./docs Directory Layout + +```bash +├── /site # Typedoc generated documentation +│ ├── assets/ # Static assets for the documentation site +│ ├── classes/ # Documentation for classes in the project +│ ├── enums/ # Documentation for enums in the project +│ ├── interfaces/ # Documentation for interfaces in the project +│ ├── media/ # Media files like images and diagrams +│ ├── modules/ # Categorized documentation for modules +│ ├── .nojekyll # Prevents GitHub Pages from processing with Jekyll +│ ├── hierarchy.html # Project structure in hierarchical format +│ ├── index.html # Main entry for the documentation site +│ └── modules.html # List of modules documented within the site │ -├── .gitignore # Specifies files and directories to be ignored by Git -├── LICENSE # License file outlining the terms under which the project is distributed -├── package-lock.json # Automatically generated file that captures the exact dependency tree -├── package.json # Project metadata and dependencies -├── README.md # Overview of the project, including its purpose, setup instructions, and usage -└── tsconfig.json # TypeScript configuration file specifying compiler options +├── CHANGELOG.md # Record of changes, updates, and version history +├── CONTRIBUTING.md # Guidelines for contributing to the project +├── DEVELOPMENT_GUIDE.md # Guide for setting up and contributing to the project +├── DOCS.md # API details, usage instructions, and best practices +└── PROJECT_STRUCTURE.md # Detailed explanation of the project directory structure +``` + +## ./src Directory Layout + +```bash +├── /enums # TypeScript enums for various poker game-related entities +├── /events # TypeScript event structures for handling and managing poker events +├── /interfaces # TypeScript interfaces for poker game entities defining structures +├── /models # Core poker models and logic implementations for the game mechanics +└── index.ts # Main export for all modules in the src directory +``` + +## ./src/enums Directory Layout + +```bash +├── /casinoEventNames # Enum for different casino-related event names +│ └── index.ts # Main export for the casino event names enum +├── /pokerPhaseNames # Enum for the names of different poker phases +│ └── index.ts # Main export for the poker phase names enum +├── /pokerSeatEventNames # Enum for seat-related event names in poker +│ └── index.ts # Main export for the poker seat event names enum +├── /rank # Enum for the ranks of playing cards +│ └── index.ts # Main export for card rank types +├── /suit # Enum for the suits of playing cards +│ └── index.ts # Main export for card suit types +└── index.ts # Aggregated export for all enums in the project +``` + +## ./src/events Directory Layout + +```bash +├── /_baseEvent # Base event structure shared across all poker-related events +│ └── index.ts # Main export for the base event structure (_BaseEvent) +├── /pokerSeatEvents # Events specific to seat management in poker (e.g., seat occupancy) +│ ├── /pokerSeatEvent # Core event structure for seat-related events +│ │ └── index.ts # Export for the poker seat event interface +│ ├── /pokerSeatOccupiedEvent # Specific event structure for seat occupancy +│ │ └── index.ts # Export for the poker seat occupied event interface +│ ├── /pokerSeatVacatedEvent # Specific event structure for vacating a seat +│ │ └── index.ts # Export for the poker seat vacated event interface +│ └── index.ts # Aggregated export for all poker seat events +└── index.ts # Main export for all events in the project +``` + +## ./src/interfaces Directory Layout + +```bash +├── /card # Interface defining the structure of a poker card (e.g., rank, suit) +│ └── index.ts # Export for card-related interfaces +├── /casino # Interface defining the structure of a casino (e.g., rooms, tables) +│ └── index.ts # Export for casino-related interfaces +├── /deck # Interface defining the structure and behavior of a deck of cards +│ └── index.ts # Export for deck-related interfaces +├── /pokerGame # Interface defining the structure of a poker game (e.g., phases, players) +│ └── index.ts # Export for poker game-related interfaces +├── /pokerPhase # Interface defining poker phases and phase transitions during gameplay +│ └── index.ts # Export for poker phase-related interfaces +├── /pokerPlayer # Interface defining the structure and behavior of a poker player +│ └── index.ts # Export for poker player-related interfaces +├── /pokerRoom # Interface defining the structure of a poker room, including table and player management +│ └── index.ts # Export for poker room-related interfaces +├── /pokerSeat # Interface defining a seat at a poker table (e.g., player sitting, bet tracking) +│ └── index.ts # Export for poker seat-related interfaces +├── /pokerTable # Interface defining the structure and behavior of a poker table (e.g., seating, blinds) +│ └── index.ts # Export for poker table-related interfaces +└── index.ts # Main export for all interfaces in the project +``` + +## ./src/models Directory Layout + +```bash +├── /card # Class implementation for a poker card, handling rank and suit logic +│ └── index.ts # Class definition and export for card logic +├── /casino # Class implementation for a casino, handling multiple rooms and tables +│ └── index.ts # Class definition and export for casino logic +├── /deck # Class implementation for a deck of cards, including shuffle and draw logic +│ └── index.ts # Class definition and export for deck logic +├── /pokerGame # Class implementation for managing poker game phases, bets, and progression +│ └── index.ts # Class definition and export for poker game logic +├── /pokerPhase # Class implementation for handling transitions between poker phases +│ └── index.ts # Class definition and export for poker phase logic +├── /pokerPlayer # Class implementation for a poker player, handling actions, chips, and hands +│ └── index.ts # Class definition and export for poker player logic +├── /pokerRoom # Class implementation for managing poker rooms and player seating +│ └── index.ts # Class definition and export for poker room logic +├── /pokerSeat # Class implementation for poker seat behavior (e.g., seating, betting) +│ └── index.ts # Class definition and export for poker seat logic +├── /pokerTable # Class implementation for poker table behavior (e.g., player seating, blinds) +│ └── index.ts # Class definition and export for poker table logic +└── index.ts # Main export for all models in the project +``` + +## ./tests Directory Layout + +```bash +├── /enums # Unit tests for enums +├── /events # Unit tests for events +├── /interfaces # Unit tests for interfaces +├── /models # Unit tests for models +└── index.test.ts # Main test file exporting all test modules +``` + +## ./tests/enums Directory Layout + +```bash +├── /casinoEventNames # Enum for different casino-related event names +│ └── index.test.ts # Test for the casino event names enum +├── /pokerPhaseNames # Enum for the names of different poker phases +│ └── index.test.ts # Test for the poker phase names enum +├── /pokerSeatEventNames # Enum for seat-related event names in poker +│ └── index.test.ts # Test for the poker seat event names enum +├── /rank # Enum for the ranks of playing cards +│ └── index.test.ts # Test for card rank types +├── /suit # Enum for the suits of playing cards +│ └── index.test.ts # Test for card suit types +└── index.test.ts # Aggregated export for all enums in the project +``` + +## ./tests/events Directory Layout + +```bash +├── /_baseEvent # Base event structure shared across all poker-related events +│ └── index.test.ts # Test for the base event structure (_BaseEvent) +├── /pokerSeatEvents # Events specific to seat management in poker (e.g., seat occupancy) +│ ├── /pokerSeatEvent # Core event structure for seat-related events +│ │ └── index.test.ts # Test for the poker seat event interface +│ ├── /pokerSeatOccupiedEvent # Specific event structure for seat occupancy +│ │ └── index.test.ts # Test for the poker seat occupied event interface +│ ├── /pokerSeatVacatedEvent # Specific event structure for vacating a seat +│ │ └── index.test.ts # Test for the poker seat vacated event interface +│ └── index.test.ts # Aggregated export for all poker seat events +└── index.test.ts # Main export for all events in the project +``` + +## ./tests/interfaces Directory Layout + +```bash +├── /card # Interface defining the structure of a poker card (e.g., rank, suit) +│ └── index.test.ts # Test for card-related interfaces +├── /casino # Interface defining the structure of a casino (e.g., rooms, tables) +│ └── index.test.ts # Test for casino-related interfaces +├── /deck # Interface defining the structure and behavior of a deck of cards +│ └── index.test.ts # Test for deck-related interfaces +├── /pokerGame # Interface defining the structure of a poker game (e.g., phases, players) +│ └── index.test.ts # Test for poker game-related interfaces +├── /pokerPhase # Interface defining poker phases and phase transitions during gameplay +│ └── index.test.ts # Test for poker phase-related interfaces +├── /pokerPlayer # Interface defining the structure and behavior of a poker player +│ └── index.test.ts # Test for poker player-related interfaces +├── /pokerRoom # Interface defining the structure of a poker room, including table and player management +│ └── index.test.ts # Test for poker room-related interfaces +├── /pokerSeat # Interface defining a seat at a poker table (e.g., player sitting, bet tracking) +│ └── index.test.ts # Test for poker seat-related interfaces +├── /pokerTable # Interface defining the structure and behavior of a poker table (e.g., seating, blinds) +│ └── index.test.ts # Test for poker table-related interfaces +└── index.test.ts # Main export for all interfaces in the project +``` + +## ./tests/models Directory Layout + +```bash +├── /card # Class implementation for a poker card, handling rank and suit logic +│ └── index.test.ts # Test for card logic +├── /casino # Class implementation for a casino, handling multiple rooms and tables +│ └── index.test.ts # Test for casino logic +├── /deck # Class implementation for a deck of cards, including shuffle and draw logic +│ └── index.test.ts # Test for deck logic +├── /pokerGame # Class implementation for managing poker game phases, bets, and progression +│ └── index.test.ts # Test for poker game logic +├── /pokerPhase # Class implementation for handling transitions between poker phases +│ └── index.test.ts # Test for poker phase logic +├── /pokerPlayer # Class implementation for a poker player, handling actions, chips, and hands +│ └── index.test.ts # Test for poker player logic +├── /pokerRoom # Class implementation for managing poker rooms and player seating +│ └── index.test.ts # Test for poker room logic +├── /pokerSeat # Class implementation for poker seat behavior (e.g., seating, betting) +│ └── index.test.ts # Test for poker seat logic +├── /pokerTable # Class implementation for poker table behavior (e.g., player seating, blinds) +│ └── index.test.ts # Test for poker table logic +└── index.test.ts # Main export for all models in the project ``` diff --git a/docs/site/assets/highlight.css b/docs/site/assets/highlight.css index 2689f2d..bb25871 100644 --- a/docs/site/assets/highlight.css +++ b/docs/site/assets/highlight.css @@ -1,24 +1,26 @@ :root { - --light-hl-0: #0000FF; - --dark-hl-0: #569CD6; - --light-hl-1: #000000; - --dark-hl-1: #D4D4D4; - --light-hl-2: #0070C1; - --dark-hl-2: #4FC1FF; - --light-hl-3: #795E26; - --dark-hl-3: #DCDCAA; - --light-hl-4: #001080; - --dark-hl-4: #9CDCFE; - --light-hl-5: #008000; - --dark-hl-5: #6A9955; - --light-hl-6: #A31515; - --dark-hl-6: #CE9178; - --light-hl-7: #AF00DB; - --dark-hl-7: #C586C0; - --light-hl-8: #098658; - --dark-hl-8: #B5CEA8; - --light-hl-9: #267F99; - --dark-hl-9: #4EC9B0; + --light-hl-0: #008000; + --dark-hl-0: #6A9955; + --light-hl-1: #AF00DB; + --dark-hl-1: #C586C0; + --light-hl-2: #000000; + --dark-hl-2: #D4D4D4; + --light-hl-3: #001080; + --dark-hl-3: #9CDCFE; + --light-hl-4: #A31515; + --dark-hl-4: #CE9178; + --light-hl-5: #0000FF; + --dark-hl-5: #569CD6; + --light-hl-6: #0070C1; + --dark-hl-6: #4FC1FF; + --light-hl-7: #795E26; + --dark-hl-7: #DCDCAA; + --light-hl-8: #267F99; + --dark-hl-8: #4EC9B0; + --light-hl-9: #098658; + --dark-hl-9: #B5CEA8; + --light-hl-10: #000000FF; + --dark-hl-10: #D4D4D4; --light-code-background: #FFFFFF; --dark-code-background: #1E1E1E; } @@ -34,6 +36,7 @@ --hl-7: var(--light-hl-7); --hl-8: var(--light-hl-8); --hl-9: var(--light-hl-9); + --hl-10: var(--light-hl-10); --code-background: var(--light-code-background); } } @@ -48,6 +51,7 @@ --hl-7: var(--dark-hl-7); --hl-8: var(--dark-hl-8); --hl-9: var(--dark-hl-9); + --hl-10: var(--dark-hl-10); --code-background: var(--dark-code-background); } } @@ -62,6 +66,7 @@ --hl-7: var(--light-hl-7); --hl-8: var(--light-hl-8); --hl-9: var(--light-hl-9); + --hl-10: var(--light-hl-10); --code-background: var(--light-code-background); } @@ -76,6 +81,7 @@ --hl-7: var(--dark-hl-7); --hl-8: var(--dark-hl-8); --hl-9: var(--dark-hl-9); + --hl-10: var(--dark-hl-10); --code-background: var(--dark-code-background); } @@ -89,4 +95,5 @@ .hl-7 { color: var(--hl-7); } .hl-8 { color: var(--hl-8); } .hl-9 { color: var(--hl-9); } +.hl-10 { color: var(--hl-10); } pre, code { background: var(--code-background); } diff --git a/docs/site/assets/navigation.js b/docs/site/assets/navigation.js index 45792ba..18c5274 100644 --- a/docs/site/assets/navigation.js +++ b/docs/site/assets/navigation.js @@ -1 +1 @@ -window.navigationData = "data:application/octet-stream;base64,H4sIAAAAAAAACqWUwW6DMBBE/2V7RW2T0irl2l64JscIIct2BQo4FTZSpCr/Xtm4CYvBtujVzDwN410ff0Dxi4IMasH4BRL4JqqCDNoz6xsun8zxY6XaBhI41YJBtk2AVnXDOi4gO94AH6RjPv+DFQyQdPOevjyn1+Tm/+T05PVbwZI/DwbIAwnyYIQ8kGFPhB9gBUv+Q18rr98KsL8YEWqhePdFKJdznL9vURe6WCiirG91gllZLaas7BdDZku+Q2igllIL1jR8Rzg0o5wwX9/QzbNAzaUWxMXCNzYfy9CM0h+rC9xbqQVRsfAEcNG3LmfvwHYojQwMQKkFUWnwKDlpDOfgwHSacZ72zHgzs6rD+T/e3RFg3cM7BgRWc34hBkD8MuD/oA2RckJxd2Cz3UXsgGVEzz8uZJLEUNyxH5IU1+IXhaUGgFIHAAA=" \ No newline at end of file +window.navigationData = "data:application/octet-stream;base64,H4sIAAAAAAAACrWbW2/bOBCF/4v6mnY3abbo5rFtUBRIiyLZPhWFoNiMI8SWUlsOulj0vy90sczbzJyRmFf78JujIW16hvT3/7LG/Gqyi8xU+80uO8kei+Y+u8g29XK/Nrs/updf3TebdXaSPZTVMrs4O8kW9+V6uTVVdvF9BLwvdmVVXz6ZqmE5LzxhDz0//fv89Z/nv0+ivMtqv/nckWCyM4SKoaIruFf16so8mTXLs0QSB7UY11P0r/WD2X69L3bmS7HhwYEUY6K+uVFspBtTNMCSC7UgVeOfGEVFui6qBxY6CLjxqL9QS1Fv6v12wcNGCc9AvcXUJHlfNjysF3DjYV+BlqIabgHm/bupvkJt3LN8k5IBEn4onRjP99nkwkBPs+gen6fnvWjG/Ha0KNPWuwHe/v5h+Xw8PJtgddRBbsm5jBg+kr1RoW3b+JrfJ/PD+5DfcNO1jY6oqygzktDjfkTZ82R4ViObru3V57pjOONbelPJ2/cgi+7OZBvrENcBx/Ww47aQvH8X8uHvRbaTAXMToXlu6C0jb9/DnDgQx0eLuAk4/kIvq6X5FdroXoYcvCt2pvtEXW7KpjFbjv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FRVCmhiKTKFXko68XodIpsResH7iH6AMFgOWFUKaEKpskZdfjpxmhVeL5ipQPzAB3cGyhmiqgh4DCaHFEHjS5f/78SRY7cv5aAOSLKBziMJkfkoZgboJPhWYqWDIz/Hu8PFRNFFQ+KSGyu7GxtiIth/euTftKzMO2fIYjDNp847Qa+TQGu4ANe5txDdznQRXTI0fTb0TYHuB4NuEHuG1O3XW3OFXZlFnCE3fJk7j7aMNXlR8Cc8o4f8YMjIGqugaEuZ99wCojoFSfU4cybPAEPvcqD+pt74yMA4lc+UIvQnQaiXdTDZrSKjsjFutjtfKQvd2Ocnr0FOioDUNVNIW2NjQ7JCbcd6HsbjB+rl8F7ircwBo6qfUG6GdsVvBOqSzFQ1B0K0o/TNuA9Md2CATaxU0Cai1TtgEWiWLeZUwp13qVfMSM+2X1rTpEsWA1KVcAst3lNrU55m26lCFjk9q+pxSFv0S3UAIvsFja9NuNd+kVSzKftdB+/0tW9DBmT/592ZGn+n0Z9KVo08T9loLfc18188Lt9tWjKuiLxfLw359Du0LMVm4MPeiq2ZbtEPFSM+PqsWzY//gfoycouvEsAAA==" \ No newline at end of file diff --git a/docs/site/assets/search.js b/docs/site/assets/search.js index d06e38b..4c0ae29 100644 --- a/docs/site/assets/search.js +++ b/docs/site/assets/search.js @@ -1 +1 @@ -window.searchData = "data:application/octet-stream;base64,H4sIAAAAAAAACq2a227jNhCG34W5FRxzSPp0V+y26HaBAt0UvRGChWsrGzU+pLKcXSDIuxekaGtGJKVx3KvsWpz/J0cfhyKlV1Htvx/EIn8VT+VuLRaQid1yW4iFKHfr4ofIxLHaiIXY7tfHTXG4db+OHuvtRmRitVkeDsVBLIR4y2IKdVE9LFfF4Xa1rNYRrdP1r/Z6v6qZnHU/fcBqyKUr6BpGZDPxvKyKXR3pY+sox6DPltVy93SZ440PYdk2cSnzw7GsLzT3Ie8zh7Genc3r/V1dlbtvF3YAhb2zEzGM1sXqqQ8je52P0UesFh+WE3QN2Ri5PiaSeXg8PjxsistMb9ool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UGonRCCBh0SpSrUVE6IVKlKGFgmYEoYRASBpQwsMxAlDAICQNKGFhmIEoYhIQBJQwsMxAlDELCgBIG01SJhRAwoICBRQaidEIIGFDAwCIDUTohBAwoYMoiA1E6VQiYooApB1iUThUCpihgylWwKJ0qBEx11kG3EMrYKqEiSyEFTFlkFMQKvgoBUxQwZZJLcMiXonypSQoRFeKlKF5qmlqIVYiXongpC4yKzigV4qUoXsoCo3Q01SFeiuKlx8lU6xAvTfHSMrWg65AuTenSkFrTdQiXpnBpB1e0DOgQLt150NKpZzsdedSibGmTevTRIVuasqUnKS51yJambOlk6dIhW5qypWfJmahDtjRlS6fZ0iFbmrJlxqlMmxAtQ9EyMpVpE6JlKFom+ehlQrQMRcuoVKZNSJahZBmdzLQJ0TKdx3iTzLSJPMk3P7k910tR1cX6U7P3ynOxtG9zXsVXvxtrj1dfBRixeH17a3dfi9c3tAGz15yx2062Ekq2Eko1QXrW/DWaJ9m8O0DdmiHNMU8Dnyii3gFS0r53PMXmDBZJoVypuZfyfw0vd+vz2xk01im6BXOejDtQbCXmrcKpX8ASKpp30q2SRImXvM48uI8GkIRBEhOehPvWAUmgTEteZh/9GzeU1wnK64wlUnbZRvCAT6xnyPAYKrsQoZs99YrGK0qeYvMlYqs4bhWZfUKfHqGcIx15qdBtN3GoJnCH1fmurdVC95GHU/A9FOoX7tjFPWteKyE8EOrA69s/Szo4QB0C3qR9ci+ZkIRCEryCe3qfgIobGopWF4gEt14hkBRvROSlF1JCA1O8Gbxz37ug+41KI/Co/rf5rgPlF1cBXmq62OGBNCHS1xPlZ7+e+CrAy9ih+YQJDRQVFsnL1flNWKuCqr9fwTVvkhxKUpMkmrNyylPwL/JR3tG9U8xudCYoWkd83QZfdZXPt/b/N7wbW3fQQKwDr4t18zEhyhWCQ/Kmb70/+FfNrQyavx4pxUt8bb+oRN1BtEtGUu4z8Vw+Fxs78Rb5/dvbf/BDeKhGLwAA"; \ No newline at end of file +window.searchData = "data:application/octet-stream;base64,H4sIAA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7BwxjI/Hwpkm8zi6HBXpGQGWWsPYOMwhxHMkQBdvSHDYcynQMLHFelXNKVPgxXzThR0F0d4yM+foxXMbSMdN3KEkzHm9g58IUd4vkP4E8uSuS3oYFLOKKREM3aeja+7X1e7XyMzMrqxhWnm8cuXOIaHOyF8DiqZ96oc1tGGgIid8mLcYf1fkjyFkzl/g4T0p7zk+bQ18wgQVoYImYbw2Y1grmrk90FG4IAJEsEJoPCg42n49smq8vsrFPMYgjOfHb/DHuLpi2LuDzw8LFdxPwnP8zGTgMNxeXyMjIQbzpkLZcnRp0BE81Nv9Szf33simvN2Qf/eTC5tass2aLhAoH3KxST9wbSFhJ9Qrsx13JMxOiqGV1IInwpK5h7qI4lj4csyLXzdt3GLhSMfr/2Pu93nf0U7F4OR3k9yBfPapOPucNyTXUIhOL4cMuDp+fi4j4N0dI6GZ+LXaBOAjA7isyy4XM+GqPgGunD9XgmeO4/HdbwLQ4Yrquq8cMuc0llzL7pPr4VRiXni2ZlNNyrI8GSOYmKab8vb5ZGMS2For/woxDwr7uyRNC0cKlhWfl3G0ooWthmt9PP11cP6od0YaP7dp5//+OP/AwQrPUpfwQEA"; \ No newline at end of file diff --git a/docs/site/classes/models__base.BaseEventEmitter.html b/docs/site/classes/models__base.BaseEventEmitter.html new file mode 100644 index 0000000..4f41fe7 --- /dev/null +++ b/docs/site/classes/models__base.BaseEventEmitter.html @@ -0,0 +1,331 @@ +
The constructor
initializes the BaseEventEmitter
class.
Static
captureValue: boolean
+Change the default captureRejections
option on all new EventEmitter
objects.
Static
Readonly
captureValue: Symbol.for('nodejs.rejection')
See how to write a custom rejection handler
.
Static
defaultBy default, a maximum of 10
listeners can be registered for any single
+event. This limit can be changed for individual EventEmitter
instances
+using the emitter.setMaxListeners(n)
method. To change the default
+for allEventEmitter
instances, the events.defaultMaxListeners
property
+can be used. If this value is not a positive number, a RangeError
is thrown.
Take caution when setting the events.defaultMaxListeners
because the
+change affects all EventEmitter
instances, including those created before
+the change is made. However, calling emitter.setMaxListeners(n)
still has
+precedence over events.defaultMaxListeners
.
This is not a hard limit. The EventEmitter
instance will allow
+more listeners to be added but will output a trace warning to stderr indicating
+that a "possible EventEmitter memory leak" has been detected. For any single
+EventEmitter
, the emitter.getMaxListeners()
and emitter.setMaxListeners()
methods can be used to
+temporarily avoid this warning:
import { EventEmitter } from 'node:events';
const emitter = new EventEmitter();
emitter.setMaxListeners(emitter.getMaxListeners() + 1);
emitter.once('event', () => {
// do stuff
emitter.setMaxListeners(Math.max(emitter.getMaxListeners() - 1, 0));
});
+
+
+The --trace-warnings
command-line flag can be used to display the
+stack trace for such warnings.
The emitted warning can be inspected with process.on('warning')
and will
+have the additional emitter
, type
, and count
properties, referring to
+the event emitter instance, the event's name and the number of attached
+listeners, respectively.
+Its name
property is set to 'MaxListenersExceededWarning'
.
Static
Readonly
errorThis symbol shall be used to install a listener for only monitoring 'error'
events. Listeners installed using this symbol are called before the regular 'error'
listeners are called.
Installing a listener using this symbol does not change the behavior once an 'error'
event is emitted. Therefore, the process will still crash if no
+regular 'error'
listener is installed.
Optional
[captureRest
...args: AnyRestAlias for emitter.on(eventName, listener)
.
Rest
...args: any[]Synchronously calls each of the listeners registered for the event named eventName
, in the order they were registered, passing the supplied arguments
+to each.
Returns true
if the event had listeners, false
otherwise.
import { EventEmitter } from 'node:events';
const myEmitter = new EventEmitter();
// First listener
myEmitter.on('event', function firstListener() {
console.log('Helloooo! first listener');
});
// Second listener
myEmitter.on('event', function secondListener(arg1, arg2) {
console.log(`event with parameters ${arg1}, ${arg2} in second listener`);
});
// Third listener
myEmitter.on('event', function thirdListener(...args) {
const parameters = args.join(', ');
console.log(`event with parameters ${parameters} in third listener`);
});
console.log(myEmitter.listeners('event'));
myEmitter.emit('event', 1, 2, 3, 4, 5);
// Prints:
// [
// [Function: firstListener],
// [Function: secondListener],
// [Function: thirdListener]
// ]
// Helloooo! first listener
// event with parameters 1, 2 in second listener
// event with parameters 1, 2, 3, 4, 5 in third listener
+
+
+Rest
...args: AnyRestThe emitEvent
method is a public method for emitting events, with an optional configuration that allows
+middleware processing. Middleware functions can intercept and transform the event before it reaches the listeners,
+allowing custom validation or data modifications.
This method enables flexible event emission with support for middleware, providing a robust event processing
+mechanism in the BaseEventEmitter
. It’s useful for customizing event behavior based on application-specific needs.
N/A
+N/A
+This method can emit any event specified by eventName
, which can then be processed by middleware functions if defined.
eventName: string
- The name of the event to emit.options: { event: { data: { [key: string]: any }; [key: string]: any; }, middlewares?: Array<(event: BaseEventInterface, next: () => void) => void | false> }
+eventName
must be a valid string.options.event
should include relevant data for the event. If middlewares
are provided, they should be functions with an event and next parameter.void
- This method does not return a value.Use this method to emit events with middleware-based customization, which allows for specific processing +logic or transformations before the event reaches listeners.
+The name of the event to emit.
+Configuration for the event and optional middleware functions.
+Optional
middlewares?: ((event: BaseEventInterface<any>, next: (() => void)) => false | void)[]Returns an array listing the events for which the emitter has registered
+listeners. The values in the array are strings or Symbol
s.
import { EventEmitter } from 'node:events';
const myEE = new EventEmitter();
myEE.on('foo', () => {});
myEE.on('bar', () => {});
const sym = Symbol('symbol');
myEE.on(sym, () => {});
console.log(myEE.eventNames());
// Prints: [ 'foo', 'bar', Symbol(symbol) ]
+
+
+Returns the current max listener value for the EventEmitter
which is either
+set by emitter.setMaxListeners(n)
or defaults to defaultMaxListeners.
Returns the number of listeners listening for the event named eventName
.
+If listener
is provided, it will return how many times the listener is found
+in the list of the listeners of the event.
The name of the event being listened for
+Optional
listener: FunctionThe event handler function
+Returns a copy of the array of listeners for the event named eventName
.
server.on('connection', (stream) => {
console.log('someone connected!');
});
console.log(util.inspect(server.listeners('connection')));
// Prints: [ [Function] ]
+
+
+Alias for emitter.removeListener()
.
Rest
...args: any[]Adds the listener
function to the end of the listeners array for the event
+named eventName
. No checks are made to see if the listener
has already
+been added. Multiple calls passing the same combination of eventName
and
+listener
will result in the listener
being added, and called, multiple times.
server.on('connection', (stream) => {
console.log('someone connected!');
});
+
+
+Returns a reference to the EventEmitter
, so that calls can be chained.
By default, event listeners are invoked in the order they are added. The emitter.prependListener()
method can be used as an alternative to add the
+event listener to the beginning of the listeners array.
import { EventEmitter } from 'node:events';
const myEE = new EventEmitter();
myEE.on('foo', () => console.log('a'));
myEE.prependListener('foo', () => console.log('b'));
myEE.emit('foo');
// Prints:
// b
// a
+
+
+The name of the event.
+The callback function
+Rest
...args: any[]Adds a one-time listener
function for the event named eventName
. The
+next time eventName
is triggered, this listener is removed and then invoked.
server.once('connection', (stream) => {
console.log('Ah, we have our first user!');
});
+
+
+Returns a reference to the EventEmitter
, so that calls can be chained.
By default, event listeners are invoked in the order they are added. The emitter.prependOnceListener()
method can be used as an alternative to add the
+event listener to the beginning of the listeners array.
import { EventEmitter } from 'node:events';
const myEE = new EventEmitter();
myEE.once('foo', () => console.log('a'));
myEE.prependOnceListener('foo', () => console.log('b'));
myEE.emit('foo');
// Prints:
// b
// a
+
+
+The name of the event.
+The callback function
+Rest
...args: any[]Adds the listener
function to the beginning of the listeners array for the
+event named eventName
. No checks are made to see if the listener
has
+already been added. Multiple calls passing the same combination of eventName
+and listener
will result in the listener
being added, and called, multiple times.
server.prependListener('connection', (stream) => {
console.log('someone connected!');
});
+
+
+Returns a reference to the EventEmitter
, so that calls can be chained.
The name of the event.
+The callback function
+Rest
...args: any[]Adds a one-timelistener
function for the event named eventName
to the beginning of the listeners array. The next time eventName
is triggered, this
+listener is removed, and then invoked.
server.prependOnceListener('connection', (stream) => {
console.log('Ah, we have our first user!');
});
+
+
+Returns a reference to the EventEmitter
, so that calls can be chained.
The name of the event.
+The callback function
+Rest
...args: any[]Returns a copy of the array of listeners for the event named eventName
,
+including any wrappers (such as those created by .once()
).
import { EventEmitter } from 'node:events';
const emitter = new EventEmitter();
emitter.once('log', () => console.log('log once'));
// Returns a new Array with a function `onceWrapper` which has a property
// `listener` which contains the original listener bound above
const listeners = emitter.rawListeners('log');
const logFnWrapper = listeners[0];
// Logs "log once" to the console and does not unbind the `once` event
logFnWrapper.listener();
// Logs "log once" to the console and removes the listener
logFnWrapper();
emitter.on('log', () => console.log('log persistently'));
// Will return a new Array with a single function bound by `.on()` above
const newListeners = emitter.rawListeners('log');
// Logs "log persistently" twice
newListeners[0]();
emitter.emit('log');
+
+
+Removes all listeners, or those of the specified eventName
.
It is bad practice to remove listeners added elsewhere in the code,
+particularly when the EventEmitter
instance was created by some other
+component or module (e.g. sockets or file streams).
Returns a reference to the EventEmitter
, so that calls can be chained.
Optional
eventName: string | symbolRemoves the specified listener
from the listener array for the event named eventName
.
const callback = (stream) => {
console.log('someone connected!');
};
server.on('connection', callback);
// ...
server.removeListener('connection', callback);
+
+
+removeListener()
will remove, at most, one instance of a listener from the
+listener array. If any single listener has been added multiple times to the
+listener array for the specified eventName
, then removeListener()
must be
+called multiple times to remove each instance.
Once an event is emitted, all listeners attached to it at the
+time of emitting are called in order. This implies that any removeListener()
or removeAllListeners()
calls after emitting and before the last listener finishes execution
+will not remove them fromemit()
in progress. Subsequent events behave as expected.
import { EventEmitter } from 'node:events';
class MyEmitter extends EventEmitter {}
const myEmitter = new MyEmitter();
const callbackA = () => {
console.log('A');
myEmitter.removeListener('event', callbackB);
};
const callbackB = () => {
console.log('B');
};
myEmitter.on('event', callbackA);
myEmitter.on('event', callbackB);
// callbackA removes listener callbackB but it will still be called.
// Internal listener array at time of emit [callbackA, callbackB]
myEmitter.emit('event');
// Prints:
// A
// B
// callbackB is now removed.
// Internal listener array [callbackA]
myEmitter.emit('event');
// Prints:
// A
+
+
+Because listeners are managed using an internal array, calling this will
+change the position indices of any listener registered after the listener
+being removed. This will not impact the order in which listeners are called,
+but it means that any copies of the listener array as returned by
+the emitter.listeners()
method will need to be recreated.
When a single function has been added as a handler multiple times for a single
+event (as in the example below), removeListener()
will remove the most
+recently added instance. In the example the once('ping')
listener is removed:
import { EventEmitter } from 'node:events';
const ee = new EventEmitter();
function pong() {
console.log('pong');
}
ee.on('ping', pong);
ee.once('ping', pong);
ee.removeListener('ping', pong);
ee.emit('ping');
ee.emit('ping');
+
+
+Returns a reference to the EventEmitter
, so that calls can be chained.
Rest
...args: any[]By default EventEmitter
s will print a warning if more than 10
listeners are
+added for a particular event. This is a useful default that helps finding
+memory leaks. The emitter.setMaxListeners()
method allows the limit to be
+modified for this specific EventEmitter
instance. The value can be set to Infinity
(or 0
) to indicate an unlimited number of listeners.
Returns a reference to the EventEmitter
, so that calls can be chained.
Static
addExperimental
Listens once to the abort
event on the provided signal
.
Listening to the abort
event on abort signals is unsafe and may
+lead to resource leaks since another third party with the signal can
+call e.stopImmediatePropagation()
. Unfortunately Node.js cannot change
+this since it would violate the web standard. Additionally, the original
+API makes it easy to forget to remove listeners.
This API allows safely using AbortSignal
s in Node.js APIs by solving these
+two issues by listening to the event such that stopImmediatePropagation
does
+not prevent the listener from running.
Returns a disposable so that it may be unsubscribed from more easily.
+import { addAbortListener } from 'node:events';
function example(signal) {
let disposable;
try {
signal.addEventListener('abort', (e) => e.stopImmediatePropagation());
disposable = addAbortListener(signal, (e) => {
// Do something when signal is aborted.
});
} finally {
disposable?.[Symbol.dispose]();
}
}
+
+
+Disposable that removes the abort
listener.
Static
getReturns a copy of the array of listeners for the event named eventName
.
For EventEmitter
s this behaves exactly the same as calling .listeners
on
+the emitter.
For EventTarget
s this is the only way to get the event listeners for the
+event target. This is useful for debugging and diagnostic purposes.
import { getEventListeners, EventEmitter } from 'node:events';
{
const ee = new EventEmitter();
const listener = () => console.log('Events are fun');
ee.on('foo', listener);
console.log(getEventListeners(ee, 'foo')); // [ [Function: listener] ]
}
{
const et = new EventTarget();
const listener = () => console.log('Events are fun');
et.addEventListener('foo', listener);
console.log(getEventListeners(et, 'foo')); // [ [Function: listener] ]
}
+
+
+Static
getReturns the currently set max amount of listeners.
+For EventEmitter
s this behaves exactly the same as calling .getMaxListeners
on
+the emitter.
For EventTarget
s this is the only way to get the max event listeners for the
+event target. If the number of event handlers on a single EventTarget exceeds
+the max set, the EventTarget will print a warning.
import { getMaxListeners, setMaxListeners, EventEmitter } from 'node:events';
{
const ee = new EventEmitter();
console.log(getMaxListeners(ee)); // 10
setMaxListeners(11, ee);
console.log(getMaxListeners(ee)); // 11
}
{
const et = new EventTarget();
console.log(getMaxListeners(et)); // 10
setMaxListeners(11, et);
console.log(getMaxListeners(et)); // 11
}
+
+
+Static
listenerA class method that returns the number of listeners for the given eventName
registered on the given emitter
.
import { EventEmitter, listenerCount } from 'node:events';
const myEmitter = new EventEmitter();
myEmitter.on('event', () => {});
myEmitter.on('event', () => {});
console.log(listenerCount(myEmitter, 'event'));
// Prints: 2
+
+
+The emitter to query
+The event name
+Static
onimport { on, EventEmitter } from 'node:events';
import process from 'node:process';
const ee = new EventEmitter();
// Emit later on
process.nextTick(() => {
ee.emit('foo', 'bar');
ee.emit('foo', 42);
});
for await (const event of on(ee, 'foo')) {
// The execution of this inner block is synchronous and it
// processes one event at a time (even with await). Do not use
// if concurrent execution is required.
console.log(event); // prints ['bar'] [42]
}
// Unreachable here
+
+
+Returns an AsyncIterator
that iterates eventName
events. It will throw
+if the EventEmitter
emits 'error'
. It removes all listeners when
+exiting the loop. The value
returned by each iteration is an array
+composed of the emitted event arguments.
An AbortSignal
can be used to cancel waiting on events:
import { on, EventEmitter } from 'node:events';
import process from 'node:process';
const ac = new AbortController();
(async () => {
const ee = new EventEmitter();
// Emit later on
process.nextTick(() => {
ee.emit('foo', 'bar');
ee.emit('foo', 42);
});
for await (const event of on(ee, 'foo', { signal: ac.signal })) {
// The execution of this inner block is synchronous and it
// processes one event at a time (even with await). Do not use
// if concurrent execution is required.
console.log(event); // prints ['bar'] [42]
}
// Unreachable here
})();
process.nextTick(() => ac.abort());
+
+
+Use the close
option to specify an array of event names that will end the iteration:
import { on, EventEmitter } from 'node:events';
import process from 'node:process';
const ee = new EventEmitter();
// Emit later on
process.nextTick(() => {
ee.emit('foo', 'bar');
ee.emit('foo', 42);
ee.emit('close');
});
for await (const event of on(ee, 'foo', { close: ['close'] })) {
console.log(event); // prints ['bar'] [42]
}
// the loop will exit after 'close' is emitted
console.log('done'); // prints 'done'
+
+
+Optional
options: StaticEventEmitterIteratorOptionsAn AsyncIterator
that iterates eventName
events emitted by the emitter
Optional
options: StaticEventEmitterIteratorOptionsStatic
onceCreates a Promise
that is fulfilled when the EventEmitter
emits the given
+event or that is rejected if the EventEmitter
emits 'error'
while waiting.
+The Promise
will resolve with an array of all the arguments emitted to the
+given event.
This method is intentionally generic and works with the web platform EventTarget interface, which has no special'error'
event
+semantics and does not listen to the 'error'
event.
import { once, EventEmitter } from 'node:events';
import process from 'node:process';
const ee = new EventEmitter();
process.nextTick(() => {
ee.emit('myevent', 42);
});
const [value] = await once(ee, 'myevent');
console.log(value);
const err = new Error('kaboom');
process.nextTick(() => {
ee.emit('error', err);
});
try {
await once(ee, 'myevent');
} catch (err) {
console.error('error happened', err);
}
+
+
+The special handling of the 'error'
event is only used when events.once()
is used to wait for another event. If events.once()
is used to wait for the
+'error'
event itself, then it is treated as any other kind of event without
+special handling:
import { EventEmitter, once } from 'node:events';
const ee = new EventEmitter();
once(ee, 'error')
.then(([err]) => console.log('ok', err.message))
.catch((err) => console.error('error', err.message));
ee.emit('error', new Error('boom'));
// Prints: ok boom
+
+
+An AbortSignal
can be used to cancel waiting for the event:
import { EventEmitter, once } from 'node:events';
const ee = new EventEmitter();
const ac = new AbortController();
async function foo(emitter, event, signal) {
try {
await once(emitter, event, { signal });
console.log('event emitted!');
} catch (error) {
if (error.name === 'AbortError') {
console.error('Waiting for the event was canceled!');
} else {
console.error('There was an error', error.message);
}
}
}
foo(ee, 'foo', ac.signal);
ac.abort(); // Abort waiting for the event
ee.emit('foo'); // Prints: Waiting for the event was canceled!
+
+
+Optional
options: StaticEventEmitterOptionsOptional
options: StaticEventEmitterOptionsStatic
setimport { setMaxListeners, EventEmitter } from 'node:events';
const target = new EventTarget();
const emitter = new EventEmitter();
setMaxListeners(5, target, emitter);
+
+
+Optional
n: numberA non-negative number. The maximum number of listeners per EventTarget
event.
Rest
...eventTargets: (EventEmitter<DefaultEventMap> | EventTarget)[]Zero or more {EventTarget} or {EventEmitter} instances. If none are specified, n
is set as the default max for all newly created {EventTarget} and {EventEmitter}
+objects.
Card
: Represents a playing card in a poker game, consisting of a rank and a suit.
-Implements the ICard
interface.
const card = new Card(Rank.Ace, Suit.Spades);
console.log(card.toString()); // "A of Spades"
+Card | casinojs Class Card
Card
+Represents a playing card in a poker game, consisting of a rank and a suit.
+Implements the CardInterface
.
+The Card
class encapsulates its properties (rank
and suit
) as private
+and provides public getter methods to access these properties.
+It also includes private setter methods for internal control over the state.
+ Index
Constructors
constructor
Implements
Index
Constructors
Methods
Constructors
constructor
- new
Card(config): Card constructor
Creates an instance of a Card
with the given rank and suit.
-Parameters
- config: CardConfig
The configuration of the card.
+
Returns Card
+
Casino
+Represents a Casino environment that manages multiple poker rooms (PokerRooms
).
+This class handles operations related to room creation, listing, removal, and searching.
A Casino serves as a central hub for organizing poker games by managing rooms. +Each room can accommodate players and maintain its own game state.
+Additionally, it extends the Node.js BaseEventEmitter
to emit events when specific actions
+occur, such as creating or removing a room.
This class implements the CasinoInterface
and inherits from the BaseEventEmitter
class,
+allowing it to emit events and conform to the defined interface structure for consistency
+and predictability.
The Casino
class emits custom events to signal room-related actions. For instance,
+when a room is created, an event casino:roomCreated
is emitted, making it easy
+to handle notifications or updates related to the Casino’s operations.
Static
captureValue: boolean
+Change the default captureRejections
option on all new EventEmitter
objects.
Static
Readonly
captureValue: Symbol.for('nodejs.rejection')
See how to write a custom rejection handler
.
Static
defaultBy default, a maximum of 10
listeners can be registered for any single
+event. This limit can be changed for individual EventEmitter
instances
+using the emitter.setMaxListeners(n)
method. To change the default
+for allEventEmitter
instances, the events.defaultMaxListeners
property
+can be used. If this value is not a positive number, a RangeError
is thrown.
Take caution when setting the events.defaultMaxListeners
because the
+change affects all EventEmitter
instances, including those created before
+the change is made. However, calling emitter.setMaxListeners(n)
still has
+precedence over events.defaultMaxListeners
.
This is not a hard limit. The EventEmitter
instance will allow
+more listeners to be added but will output a trace warning to stderr indicating
+that a "possible EventEmitter memory leak" has been detected. For any single
+EventEmitter
, the emitter.getMaxListeners()
and emitter.setMaxListeners()
methods can be used to
+temporarily avoid this warning:
import { EventEmitter } from 'node:events';
const emitter = new EventEmitter();
emitter.setMaxListeners(emitter.getMaxListeners() + 1);
emitter.once('event', () => {
// do stuff
emitter.setMaxListeners(Math.max(emitter.getMaxListeners() - 1, 0));
});
+
+
+The --trace-warnings
command-line flag can be used to display the
+stack trace for such warnings.
The emitted warning can be inspected with process.on('warning')
and will
+have the additional emitter
, type
, and count
properties, referring to
+the event emitter instance, the event's name and the number of attached
+listeners, respectively.
+Its name
property is set to 'MaxListenersExceededWarning'
.
Static
Readonly
errorThis symbol shall be used to install a listener for only monitoring 'error'
events. Listeners installed using this symbol are called before the regular 'error'
listeners are called.
Installing a listener using this symbol does not change the behavior once an 'error'
event is emitted. Therefore, the process will still crash if no
+regular 'error'
listener is installed.
Protected
_addAdds a single PokerRoom
instance to the Casino's list of managed rooms.
N/A
N/A
Allows dynamic expansion of rooms within the Casino environment, enabling additional gaming options for players.
+CasinoEvents.ROOM_ADDED
event after adding a room.room
: The PokerRoomInterface
instance representing the room to be added.room
parameter must be a valid instance implementing PokerRoomInterface
.Useful when adding a new room to the Casino in response to game demand or configuration changes.
+The PokerRoom
instance to add.
Protected
_addAdds multiple PokerRoom
instances to the Casino's list of managed rooms.
N/A
N/A
Enables efficient management of batch room additions within the Casino, ensuring all rooms are processed together.
+CasinoEvents.ROOMS_SET
event once all rooms are added.rooms
: An array of PokerRoomInterface
instances to add.rooms
array must be a valid PokerRoomInterface
instance.Useful in scenarios where multiple rooms need to be added to the Casino at once, such as during setup or a bulk update.
+Array of PokerRoomInterface
instances to add.
Protected
_createCreates a new PokerRoom
instance based on the provided configuration and adds it to the Casino's rooms list.
N/A
N/A
Allows the Casino to dynamically create new rooms as needed by providing specific room configurations.
+CasinoEvents.ROOM_CREATED
event, enabling listeners to respond to the creation of a new room.config
: A PokerRoomConfig
object containing details like name
, tableSize
, smallBlind
, and bigBlind
.N/A
PokerRoomInterface
instance.Primarily used within subclasses or protected methods to dynamically create and add rooms to the Casino.
+Configuration settings for creating a new PokerRoom
.
class SpecialCasino extends Casino {
public createSpecialRoom(config: PokerRoomConfig): PokerRoomInterface {
return this._createRoom(config);
}
}
const specialCasino = new SpecialCasino();
const newRoom = specialCasino.createSpecialRoom({ name: "Champions Lounge", tableSize: 10, smallBlind: 100, bigBlind: 200 });
console.log(newRoom.getName()); // Outputs: "Champions Lounge"
+
+
+Protected
_deleteRemoves a PokerRoom
from the Casino's list based on the room's index, providing controlled removal of rooms.
N/A
N/A
Allows for the safe removal of a specific room from the Casino’s list.
+CasinoEvents.ROOM_DELETED
event once the room is successfully removed.index
: The zero-based index of the room to remove.index
must be valid within the bounds of the __rooms
array.Primarily used for controlled removal of a specific room from the Casino's room list.
+The index of the room to be removed.
+Protected
_setSets the complete list of rooms managed by the Casino with a new array of PokerRoomInterface
objects.
N/A
N/A
This protected method allows subclasses of Casino
to modify the entire __rooms
property, which can be used
+when needing to replace or reset the Casino's room list.
CasinoEvents.ROOMS_SET
event, allowing external listeners to respond to room updates.rooms
: An array of PokerRoomInterface
instances representing the new rooms for the Casino.rooms
array should contain at least one room (rooms.length >= 1
).This method is useful when an update or replacement of all rooms is needed, such as during initialization +or batch updates.
+Array of new rooms to set in the Casino.
+class ExtendedCasino extends Casino {
public resetRooms(newRooms: PokerRoomInterface[]): PokerRoomInterface[] {
return this._setRooms(newRooms);
}
}
const extendedCasino = new ExtendedCasino();
const rooms = [new PokerRoom({ name: "VIP", tableSize: 8, smallBlind: 50, bigBlind: 100 })];
extendedCasino.resetRooms(rooms); // Resets the Casino's rooms list
+
+
+Optional
[captureRest
...args: AnyRestAlias for emitter.on(eventName, listener)
.
Rest
...args: any[]Adds a new PokerRoom
instance to the Casino's list of managed rooms, enabling dynamic expansion
+of rooms within the Casino environment.
N/A
N/A
This method provides a flexible mechanism for expanding the Casino's room offerings by allowing new +rooms to be added as required, thereby supporting various gaming scenarios and player demand.
+N/A
room
- A PokerRoomInterface
instance representing the room to be added to the Casino’s list.room
parameter must be a valid instance implementing PokerRoomInterface
.true
to confirm that the room has been successfully added to the Casino.Typically used in scenarios where the Casino environment needs to expand by adding more gaming rooms.
+The PokerRoom
instance to add.
true
when the room has been added successfully.Adds multiple PokerRoom
instances to the Casino's list of managed rooms in a single operation, enabling
+efficient and scalable room management.
N/A
N/A
This method provides a convenient way to add several rooms at once, allowing the Casino's environment to +scale in response to gaming demand or operational changes.
+N/A
rooms
: An array of PokerRoomInterface
instances representing the rooms to be added to the Casino.rooms
array must be a valid PokerRoomInterface
instance.true
when all rooms have been added successfully.Typically used in scenarios where multiple rooms need to be added to the Casino simultaneously, such as +during batch operations or initial setup.
+Array of PokerRoomInterface
instances to add.
true
when all rooms have been successfully added.const casino = new Casino();
const rooms = [
new PokerRoom({ name: "Room1", tableSize: 5, smallBlind: 5, bigBlind: 10 }),
new PokerRoom({ name: "Room2", tableSize: 6, smallBlind: 10, bigBlind: 20 })
];
const success = casino.addRooms(rooms);
console.log(success); // true if both rooms were added successfully
+
+
+Creates a new PokerRoom
within the Casino and adds it to the list of rooms.
Implements the createRoom
method of CasinoInterface
.
N/A
Enables the dynamic creation and addition of a PokerRoom
to the Casino, expanding the Casino’s managed rooms as required.
+This facilitates flexible game setup and room management in response to user needs.
casino:roomCreated
: This custom event is emitted once the room is successfully added.
+Listeners to this event can respond with actions, such as logging or notifying users.config
: A configuration object containing details like the room’s name, table size, small blind, and big blind values.name
, tableSize
, smallBlind
, and bigBlind
.PokerRoom
instance, confirming its addition to the Casino.This method creates a new room based on the provided configuration, then pushes it into the Casino’s room list.
+After adding the room, it emits a casino:roomCreated
event for any listeners tracking room creation.
A configuration object with properties like the room name, table size, small blind, and big blind values.
+PokerRoom
instance.Removes a PokerRoom
from the Casino's list of managed rooms based on the room's name, enabling dynamic
+contraction of the Casino environment as required.
N/A
N/A
Allows the Casino environment to remain current by dynamically removing rooms that are no longer active +or needed. This supports a clean and manageable set of active rooms within the Casino.
+casino:roomRemoved
event when a room is successfully removed. This event can be used
+to trigger updates, logging, or notifications.roomName
: A string representing the name of the PokerRoom
to be removed from the Casino.roomName
parameter should match the name
property of an existing room for successful deletion.true
if the room was successfully removed, or false
if no room with the specified name was found.Use this method when removing a room that is no longer active or required, ensuring that only +currently used rooms remain managed by the Casino.
+The name of the PokerRoom
to be removed.
true
if the room was removed; false
if not found.Synchronously calls each of the listeners registered for the event named eventName
, in the order they were registered, passing the supplied arguments
+to each.
Returns true
if the event had listeners, false
otherwise.
import { EventEmitter } from 'node:events';
const myEmitter = new EventEmitter();
// First listener
myEmitter.on('event', function firstListener() {
console.log('Helloooo! first listener');
});
// Second listener
myEmitter.on('event', function secondListener(arg1, arg2) {
console.log(`event with parameters ${arg1}, ${arg2} in second listener`);
});
// Third listener
myEmitter.on('event', function thirdListener(...args) {
const parameters = args.join(', ');
console.log(`event with parameters ${parameters} in third listener`);
});
console.log(myEmitter.listeners('event'));
myEmitter.emit('event', 1, 2, 3, 4, 5);
// Prints:
// [
// [Function: firstListener],
// [Function: secondListener],
// [Function: thirdListener]
// ]
// Helloooo! first listener
// event with parameters 1, 2 in second listener
// event with parameters 1, 2, 3, 4, 5 in third listener
+
+
+Rest
...args: AnyRestThe emitEvent
method is a public method for emitting events, with an optional configuration that allows
+middleware processing. Middleware functions can intercept and transform the event before it reaches the listeners,
+allowing custom validation or data modifications.
This method enables flexible event emission with support for middleware, providing a robust event processing
+mechanism in the BaseEventEmitter
. It’s useful for customizing event behavior based on application-specific needs.
N/A
+N/A
+This method can emit any event specified by eventName
, which can then be processed by middleware functions if defined.
eventName: string
- The name of the event to emit.options: { event: { data: { [key: string]: any }; [key: string]: any; }, middlewares?: Array<(event: BaseEventInterface, next: () => void) => void | false> }
+eventName
must be a valid string.options.event
should include relevant data for the event. If middlewares
are provided, they should be functions with an event and next parameter.void
- This method does not return a value.Use this method to emit events with middleware-based customization, which allows for specific processing +logic or transformations before the event reaches listeners.
+The name of the event to emit.
+Configuration for the event and optional middleware functions.
+Optional
middlewares?: ((event: BaseEventInterface<any>, next: (() => void)) => false | void)[]Returns an array listing the events for which the emitter has registered
+listeners. The values in the array are strings or Symbol
s.
import { EventEmitter } from 'node:events';
const myEE = new EventEmitter();
myEE.on('foo', () => {});
myEE.on('bar', () => {});
const sym = Symbol('symbol');
myEE.on(sym, () => {});
console.log(myEE.eventNames());
// Prints: [ 'foo', 'bar', Symbol(symbol) ]
+
+
+Returns the current max listener value for the EventEmitter
which is either
+set by emitter.setMaxListeners(n)
or defaults to defaultMaxListeners.
Retrieves a specific PokerRoom
based on its position within the Casino’s list of rooms.
N/A
N/A
This method provides direct access to a single PokerRoom
by index, allowing for targeted retrieval of rooms,
+which can be useful for room-specific operations or when sequentially processing rooms.
N/A
index
: A zero-based index representing the position of the desired PokerRoom
in the Casino’s room list.__rooms
array (i.e., 0 <= index < __rooms.length
).undefined
return.PokerRoomInterface
instance located at the specified index.undefined
if the provided index is out of bounds.Use this method when you need to access a particular room directly by its index in the Casino’s list of rooms. +This can be useful in looped operations or when accessing rooms based on their position in the list.
+The zero-based index of the desired room in the Casino’s room list.
+PokerRoom
at the specified index or undefined
if the index is out of bounds.Retrieves the full list of rooms currently managed by the Casino.
+Implements the getRooms
method of CasinoInterface
.
N/A
Provides access to the Casino's list of rooms, allowing external components or systems to retrieve and display +information on all currently managed poker rooms.
+N/A
N/A
N/A
PokerRoomInterface
instances currently managed by the Casino.This method is useful when a complete list of active rooms is needed, such as when displaying the Casino's +available games or managing room states.
+PokerRoom
objects in the Casino.Checks if a provided index is within the valid range of the Casino’s room list, helping avoid out-of-bounds errors.
+isValidIndex
method from CasinoInterface
.
N/A
This method validates an index before it's used to access or modify a room in the Casino’s list, protecting +against out-of-bound errors. It is useful in any operations that involve room access by index.
+N/A
index
: A zero-based integer representing the position of a room in the Casino's managed list.index
should be a non-negative integer within the range [0, roomCount - 1]
.true
if the index is valid.Error
if the index is out of range, providing a descriptive message.Use this method before performing operations that involve accessing a room by index. This helps prevent +out-of-bound errors in index-based room access.
+The zero-based index to validate.
+true
if the index is within bounds.Returns the number of listeners listening for the event named eventName
.
+If listener
is provided, it will return how many times the listener is found
+in the list of the listeners of the event.
The name of the event being listened for
+Optional
listener: FunctionThe event handler function
+Returns a copy of the array of listeners for the event named eventName
.
server.on('connection', (stream) => {
console.log('someone connected!');
});
console.log(util.inspect(server.listeners('connection')));
// Prints: [ [Function] ]
+
+
+Alias for emitter.removeListener()
.
Rest
...args: any[]Adds the listener
function to the end of the listeners array for the event
+named eventName
. No checks are made to see if the listener
has already
+been added. Multiple calls passing the same combination of eventName
and
+listener
will result in the listener
being added, and called, multiple times.
server.on('connection', (stream) => {
console.log('someone connected!');
});
+
+
+Returns a reference to the EventEmitter
, so that calls can be chained.
By default, event listeners are invoked in the order they are added. The emitter.prependListener()
method can be used as an alternative to add the
+event listener to the beginning of the listeners array.
import { EventEmitter } from 'node:events';
const myEE = new EventEmitter();
myEE.on('foo', () => console.log('a'));
myEE.prependListener('foo', () => console.log('b'));
myEE.emit('foo');
// Prints:
// b
// a
+
+
+The name of the event.
+The callback function
+Rest
...args: any[]Adds a one-time listener
function for the event named eventName
. The
+next time eventName
is triggered, this listener is removed and then invoked.
server.once('connection', (stream) => {
console.log('Ah, we have our first user!');
});
+
+
+Returns a reference to the EventEmitter
, so that calls can be chained.
By default, event listeners are invoked in the order they are added. The emitter.prependOnceListener()
method can be used as an alternative to add the
+event listener to the beginning of the listeners array.
import { EventEmitter } from 'node:events';
const myEE = new EventEmitter();
myEE.once('foo', () => console.log('a'));
myEE.prependOnceListener('foo', () => console.log('b'));
myEE.emit('foo');
// Prints:
// b
// a
+
+
+The name of the event.
+The callback function
+Rest
...args: any[]Adds the listener
function to the beginning of the listeners array for the
+event named eventName
. No checks are made to see if the listener
has
+already been added. Multiple calls passing the same combination of eventName
+and listener
will result in the listener
being added, and called, multiple times.
server.prependListener('connection', (stream) => {
console.log('someone connected!');
});
+
+
+Returns a reference to the EventEmitter
, so that calls can be chained.
The name of the event.
+The callback function
+Rest
...args: any[]Adds a one-timelistener
function for the event named eventName
to the beginning of the listeners array. The next time eventName
is triggered, this
+listener is removed, and then invoked.
server.prependOnceListener('connection', (stream) => {
console.log('Ah, we have our first user!');
});
+
+
+Returns a reference to the EventEmitter
, so that calls can be chained.
The name of the event.
+The callback function
+Rest
...args: any[]Returns a copy of the array of listeners for the event named eventName
,
+including any wrappers (such as those created by .once()
).
import { EventEmitter } from 'node:events';
const emitter = new EventEmitter();
emitter.once('log', () => console.log('log once'));
// Returns a new Array with a function `onceWrapper` which has a property
// `listener` which contains the original listener bound above
const listeners = emitter.rawListeners('log');
const logFnWrapper = listeners[0];
// Logs "log once" to the console and does not unbind the `once` event
logFnWrapper.listener();
// Logs "log once" to the console and removes the listener
logFnWrapper();
emitter.on('log', () => console.log('log persistently'));
// Will return a new Array with a single function bound by `.on()` above
const newListeners = emitter.rawListeners('log');
// Logs "log persistently" twice
newListeners[0]();
emitter.emit('log');
+
+
+Removes all listeners, or those of the specified eventName
.
It is bad practice to remove listeners added elsewhere in the code,
+particularly when the EventEmitter
instance was created by some other
+component or module (e.g. sockets or file streams).
Returns a reference to the EventEmitter
, so that calls can be chained.
Optional
eventName: string | symbolRemoves the specified listener
from the listener array for the event named eventName
.
const callback = (stream) => {
console.log('someone connected!');
};
server.on('connection', callback);
// ...
server.removeListener('connection', callback);
+
+
+removeListener()
will remove, at most, one instance of a listener from the
+listener array. If any single listener has been added multiple times to the
+listener array for the specified eventName
, then removeListener()
must be
+called multiple times to remove each instance.
Once an event is emitted, all listeners attached to it at the
+time of emitting are called in order. This implies that any removeListener()
or removeAllListeners()
calls after emitting and before the last listener finishes execution
+will not remove them fromemit()
in progress. Subsequent events behave as expected.
import { EventEmitter } from 'node:events';
class MyEmitter extends EventEmitter {}
const myEmitter = new MyEmitter();
const callbackA = () => {
console.log('A');
myEmitter.removeListener('event', callbackB);
};
const callbackB = () => {
console.log('B');
};
myEmitter.on('event', callbackA);
myEmitter.on('event', callbackB);
// callbackA removes listener callbackB but it will still be called.
// Internal listener array at time of emit [callbackA, callbackB]
myEmitter.emit('event');
// Prints:
// A
// B
// callbackB is now removed.
// Internal listener array [callbackA]
myEmitter.emit('event');
// Prints:
// A
+
+
+Because listeners are managed using an internal array, calling this will
+change the position indices of any listener registered after the listener
+being removed. This will not impact the order in which listeners are called,
+but it means that any copies of the listener array as returned by
+the emitter.listeners()
method will need to be recreated.
When a single function has been added as a handler multiple times for a single
+event (as in the example below), removeListener()
will remove the most
+recently added instance. In the example the once('ping')
listener is removed:
import { EventEmitter } from 'node:events';
const ee = new EventEmitter();
function pong() {
console.log('pong');
}
ee.on('ping', pong);
ee.once('ping', pong);
ee.removeListener('ping', pong);
ee.emit('ping');
ee.emit('ping');
+
+
+Returns a reference to the EventEmitter
, so that calls can be chained.
Rest
...args: any[]Returns the total number of PokerRoom
instances currently managed by the Casino.
Part of CasinoInterface
, ensuring standardization across implementations of the Casino class.
N/A
Provides a reliable way to retrieve the number of active poker rooms managed by the Casino. Useful for +general management, reporting, and in situations where the Casino’s room capacity or state must be assessed.
+N/A
N/A
- This method does not accept any parameters.
N/A
Use this method whenever a precise count of rooms is required, such as when iterating through rooms +or validating bounds.
+By default EventEmitter
s will print a warning if more than 10
listeners are
+added for a particular event. This is a useful default that helps finding
+memory leaks. The emitter.setMaxListeners()
method allows the limit to be
+modified for this specific EventEmitter
instance. The value can be set to Infinity
(or 0
) to indicate an unlimited number of listeners.
Returns a reference to the EventEmitter
, so that calls can be chained.
Sets the list of rooms managed by the Casino. This method is typically used to replace or update +the entire list of poker rooms in the casino.
+Implements the setRooms
method of CasinoInterface
.
N/A
Provides a way to update the current list of rooms managed by the Casino, ensuring a consistent and up-to-date +list of poker rooms as defined by the casino’s configuration.
+N/A
: No event
is emitted by this method.rooms
: An array of PokerRoomInterface
instances, representing individual poker rooms in the Casino.rooms
array must contain at least one room (i.e., rooms.length >= 1
).true
when the rooms have been successfully set.This method accepts an array of PokerRoomInterface
objects, representing poker rooms to manage in the casino.
_setRooms
method to update the private __rooms
property securely.The new list of poker rooms to be managed by the Casino.
+true
when the rooms have been successfully set.Retrieves the total count of rooms managed by the Casino, enabling easy access to the room quantity.
+N/A
- This method is unique to the Casino class and does not implement any other methods.
N/A
- This method does not override any superclass or parent methods.
The size
method provides a shortcut to access the number of poker rooms currently managed by the Casino.
+This method is useful for quickly obtaining the count of active rooms, which can help in managing or displaying
+the Casino's state.
N/A
N/A
- This method does not require any input parameters.
N/A
Call this method when a quick count of managed rooms is needed, especially for UI updates or managing limits.
+Static
addExperimental
Listens once to the abort
event on the provided signal
.
Listening to the abort
event on abort signals is unsafe and may
+lead to resource leaks since another third party with the signal can
+call e.stopImmediatePropagation()
. Unfortunately Node.js cannot change
+this since it would violate the web standard. Additionally, the original
+API makes it easy to forget to remove listeners.
This API allows safely using AbortSignal
s in Node.js APIs by solving these
+two issues by listening to the event such that stopImmediatePropagation
does
+not prevent the listener from running.
Returns a disposable so that it may be unsubscribed from more easily.
+import { addAbortListener } from 'node:events';
function example(signal) {
let disposable;
try {
signal.addEventListener('abort', (e) => e.stopImmediatePropagation());
disposable = addAbortListener(signal, (e) => {
// Do something when signal is aborted.
});
} finally {
disposable?.[Symbol.dispose]();
}
}
+
+
+Disposable that removes the abort
listener.
Static
getReturns a copy of the array of listeners for the event named eventName
.
For EventEmitter
s this behaves exactly the same as calling .listeners
on
+the emitter.
For EventTarget
s this is the only way to get the event listeners for the
+event target. This is useful for debugging and diagnostic purposes.
import { getEventListeners, EventEmitter } from 'node:events';
{
const ee = new EventEmitter();
const listener = () => console.log('Events are fun');
ee.on('foo', listener);
console.log(getEventListeners(ee, 'foo')); // [ [Function: listener] ]
}
{
const et = new EventTarget();
const listener = () => console.log('Events are fun');
et.addEventListener('foo', listener);
console.log(getEventListeners(et, 'foo')); // [ [Function: listener] ]
}
+
+
+Static
getReturns the currently set max amount of listeners.
+For EventEmitter
s this behaves exactly the same as calling .getMaxListeners
on
+the emitter.
For EventTarget
s this is the only way to get the max event listeners for the
+event target. If the number of event handlers on a single EventTarget exceeds
+the max set, the EventTarget will print a warning.
import { getMaxListeners, setMaxListeners, EventEmitter } from 'node:events';
{
const ee = new EventEmitter();
console.log(getMaxListeners(ee)); // 10
setMaxListeners(11, ee);
console.log(getMaxListeners(ee)); // 11
}
{
const et = new EventTarget();
console.log(getMaxListeners(et)); // 10
setMaxListeners(11, et);
console.log(getMaxListeners(et)); // 11
}
+
+
+Static
listenerA class method that returns the number of listeners for the given eventName
registered on the given emitter
.
import { EventEmitter, listenerCount } from 'node:events';
const myEmitter = new EventEmitter();
myEmitter.on('event', () => {});
myEmitter.on('event', () => {});
console.log(listenerCount(myEmitter, 'event'));
// Prints: 2
+
+
+The emitter to query
+The event name
+Static
onimport { on, EventEmitter } from 'node:events';
import process from 'node:process';
const ee = new EventEmitter();
// Emit later on
process.nextTick(() => {
ee.emit('foo', 'bar');
ee.emit('foo', 42);
});
for await (const event of on(ee, 'foo')) {
// The execution of this inner block is synchronous and it
// processes one event at a time (even with await). Do not use
// if concurrent execution is required.
console.log(event); // prints ['bar'] [42]
}
// Unreachable here
+
+
+Returns an AsyncIterator
that iterates eventName
events. It will throw
+if the EventEmitter
emits 'error'
. It removes all listeners when
+exiting the loop. The value
returned by each iteration is an array
+composed of the emitted event arguments.
An AbortSignal
can be used to cancel waiting on events:
import { on, EventEmitter } from 'node:events';
import process from 'node:process';
const ac = new AbortController();
(async () => {
const ee = new EventEmitter();
// Emit later on
process.nextTick(() => {
ee.emit('foo', 'bar');
ee.emit('foo', 42);
});
for await (const event of on(ee, 'foo', { signal: ac.signal })) {
// The execution of this inner block is synchronous and it
// processes one event at a time (even with await). Do not use
// if concurrent execution is required.
console.log(event); // prints ['bar'] [42]
}
// Unreachable here
})();
process.nextTick(() => ac.abort());
+
+
+Use the close
option to specify an array of event names that will end the iteration:
import { on, EventEmitter } from 'node:events';
import process from 'node:process';
const ee = new EventEmitter();
// Emit later on
process.nextTick(() => {
ee.emit('foo', 'bar');
ee.emit('foo', 42);
ee.emit('close');
});
for await (const event of on(ee, 'foo', { close: ['close'] })) {
console.log(event); // prints ['bar'] [42]
}
// the loop will exit after 'close' is emitted
console.log('done'); // prints 'done'
+
+
+Optional
options: StaticEventEmitterIteratorOptionsAn AsyncIterator
that iterates eventName
events emitted by the emitter
Optional
options: StaticEventEmitterIteratorOptionsStatic
onceCreates a Promise
that is fulfilled when the EventEmitter
emits the given
+event or that is rejected if the EventEmitter
emits 'error'
while waiting.
+The Promise
will resolve with an array of all the arguments emitted to the
+given event.
This method is intentionally generic and works with the web platform EventTarget interface, which has no special'error'
event
+semantics and does not listen to the 'error'
event.
import { once, EventEmitter } from 'node:events';
import process from 'node:process';
const ee = new EventEmitter();
process.nextTick(() => {
ee.emit('myevent', 42);
});
const [value] = await once(ee, 'myevent');
console.log(value);
const err = new Error('kaboom');
process.nextTick(() => {
ee.emit('error', err);
});
try {
await once(ee, 'myevent');
} catch (err) {
console.error('error happened', err);
}
+
+
+The special handling of the 'error'
event is only used when events.once()
is used to wait for another event. If events.once()
is used to wait for the
+'error'
event itself, then it is treated as any other kind of event without
+special handling:
import { EventEmitter, once } from 'node:events';
const ee = new EventEmitter();
once(ee, 'error')
.then(([err]) => console.log('ok', err.message))
.catch((err) => console.error('error', err.message));
ee.emit('error', new Error('boom'));
// Prints: ok boom
+
+
+An AbortSignal
can be used to cancel waiting for the event:
import { EventEmitter, once } from 'node:events';
const ee = new EventEmitter();
const ac = new AbortController();
async function foo(emitter, event, signal) {
try {
await once(emitter, event, { signal });
console.log('event emitted!');
} catch (error) {
if (error.name === 'AbortError') {
console.error('Waiting for the event was canceled!');
} else {
console.error('There was an error', error.message);
}
}
}
foo(ee, 'foo', ac.signal);
ac.abort(); // Abort waiting for the event
ee.emit('foo'); // Prints: Waiting for the event was canceled!
+
+
+Optional
options: StaticEventEmitterOptionsOptional
options: StaticEventEmitterOptionsStatic
setimport { setMaxListeners, EventEmitter } from 'node:events';
const target = new EventTarget();
const emitter = new EventEmitter();
setMaxListeners(5, target, emitter);
+
+
+Optional
n: numberA non-negative number. The maximum number of listeners per EventTarget
event.
Rest
...eventTargets: (EventEmitter<DefaultEventMap> | EventTarget)[]Zero or more {EventTarget} or {EventEmitter} instances. If none are specified, n
is set as the default max for all newly created {EventTarget} and {EventEmitter}
+objects.
Deck
: Represents a deck of 52 playing cards used in poker games.
-This class extends EventEmitter
and implements the IDeck
interface.
const deck = new Deck();
deck.on('deck:shuffled', () => console.log('Deck has been shuffled.'));
deck.shuffle();
const card = deck.draw();
console.log(card?.toString());
+Deck | casinojs Class Deck
Deck
+Represents a deck of 52 playing cards used in poker games.
+This class extends BaseEventEmitter
and implements the DeckInterface
interface.
+The Deck
class provides methods to shuffle the deck, draw cards, and emits
+events for important actions like shuffling and drawing cards.
+Hierarchy
- EventEmitter
- Deck
Implements
Index
Constructors
Hierarchy (view full)
- BaseEventEmitter
- Deck
Implements
Index
Constructors
Properties
capture Rejections
capture Rejection Symbol
default Max Listeners
@@ -12,7 +15,9 @@
add Listener
draw
emit
+emit Event
event Names
+get Cards
get Max Listeners
listener Count
listeners
@@ -33,19 +38,19 @@
on
once
set Max Listeners
- Properties
Static
capture Rejections
capture Rejections: booleanValue: boolean
+ Properties
Static
capture Rejections
capture Rejections: booleanValue: boolean
Change the default captureRejections
option on all new EventEmitter
objects.
Static
Readonly
capture Rejection Symbol
Value: Symbol.for('nodejs.rejection')
+Static
Readonly
capture Rejection Symbol
Value: Symbol.for('nodejs.rejection')
See how to write a custom rejection handler
.
Static
default Max Listeners
default Max Listeners: numberBy default, a maximum of 10
listeners can be registered for any single
+
Static
defaultBy default, a maximum of 10
listeners can be registered for any single
event. This limit can be changed for individual EventEmitter
instances
using the emitter.setMaxListeners(n)
method. To change the default
for allEventEmitter
instances, the events.defaultMaxListeners
property
@@ -59,7 +64,7 @@
that a "possible EventEmitter memory leak" has been detected. For any single
EventEmitter
, the emitter.getMaxListeners()
and emitter.setMaxListeners()
methods can be used to
temporarily avoid this warning:
import { EventEmitter } from 'node:events';
const emitter = new EventEmitter();
emitter.setMaxListeners(emitter.getMaxListeners() + 1);
emitter.once('event', () => {
// do stuff
emitter.setMaxListeners(Math.max(emitter.getMaxListeners() - 1, 0));
});
+import { EventEmitter } from 'node:events';
const emitter = new EventEmitter();
emitter.setMaxListeners(emitter.getMaxListeners() + 1);
emitter.once('event', () => {
// do stuff
emitter.setMaxListeners(Math.max(emitter.getMaxListeners() - 1, 0));
});
The --trace-warnings
command-line flag can be used to display the
@@ -70,113 +75,150 @@
listeners, respectively.
Its name
property is set to 'MaxListenersExceededWarning'
.
Static
Readonly
errorThis symbol shall be used to install a listener for only monitoring 'error'
events. Listeners installed using this symbol are called before the regular 'error'
listeners are called.
Static
Readonly
errorThis symbol shall be used to install a listener for only monitoring 'error'
events. Listeners installed using this symbol are called before the regular 'error'
listeners are called.
Installing a listener using this symbol does not change the behavior once an 'error'
event is emitted. Therefore, the process will still crash if no
regular 'error'
listener is installed.
Optional
[captureRest
...args: AnyRestAlias for emitter.on(eventName, listener)
.
Rest
...args: any[]draw
Draws a card from the top of the deck.
-Removes and returns the top card from the deck, or undefined
if the deck is empty.
const deck = new Deck();
const drawnCard = deck.draw();
console.log(drawnCard?.toString());
+Removes and returns the top card from the deck, or undefined
if the deck is empty.
+deck:drawn
: Emits a deck:drawn
event when a card is drawn.
+
Returns the drawn card or undefined
if no cards remain.
Synchronously calls each of the listeners registered for the event named eventName
, in the order they were registered, passing the supplied arguments
+
Synchronously calls each of the listeners registered for the event named eventName
, in the order they were registered, passing the supplied arguments
to each.
Returns true
if the event had listeners, false
otherwise.
import { EventEmitter } from 'node:events';
const myEmitter = new EventEmitter();
// First listener
myEmitter.on('event', function firstListener() {
console.log('Helloooo! first listener');
});
// Second listener
myEmitter.on('event', function secondListener(arg1, arg2) {
console.log(`event with parameters ${arg1}, ${arg2} in second listener`);
});
// Third listener
myEmitter.on('event', function thirdListener(...args) {
const parameters = args.join(', ');
console.log(`event with parameters ${parameters} in third listener`);
});
console.log(myEmitter.listeners('event'));
myEmitter.emit('event', 1, 2, 3, 4, 5);
// Prints:
// [
// [Function: firstListener],
// [Function: secondListener],
// [Function: thirdListener]
// ]
// Helloooo! first listener
// event with parameters 1, 2 in second listener
// event with parameters 1, 2, 3, 4, 5 in third listener
+import { EventEmitter } from 'node:events';
const myEmitter = new EventEmitter();
// First listener
myEmitter.on('event', function firstListener() {
console.log('Helloooo! first listener');
});
// Second listener
myEmitter.on('event', function secondListener(arg1, arg2) {
console.log(`event with parameters ${arg1}, ${arg2} in second listener`);
});
// Third listener
myEmitter.on('event', function thirdListener(...args) {
const parameters = args.join(', ');
console.log(`event with parameters ${parameters} in third listener`);
});
console.log(myEmitter.listeners('event'));
myEmitter.emit('event', 1, 2, 3, 4, 5);
// Prints:
// [
// [Function: firstListener],
// [Function: secondListener],
// [Function: thirdListener]
// ]
// Helloooo! first listener
// event with parameters 1, 2 in second listener
// event with parameters 1, 2, 3, 4, 5 in third listener
Rest
...args: AnyRestThe emitEvent
method is a public method for emitting events, with an optional configuration that allows
+middleware processing. Middleware functions can intercept and transform the event before it reaches the listeners,
+allowing custom validation or data modifications.
This method enables flexible event emission with support for middleware, providing a robust event processing
+mechanism in the BaseEventEmitter
. It’s useful for customizing event behavior based on application-specific needs.
N/A
+N/A
+This method can emit any event specified by eventName
, which can then be processed by middleware functions if defined.
eventName: string
- The name of the event to emit.options: { event: { data: { [key: string]: any }; [key: string]: any; }, middlewares?: Array<(event: BaseEventInterface, next: () => void) => void | false> }
+eventName
must be a valid string.options.event
should include relevant data for the event. If middlewares
are provided, they should be functions with an event and next parameter.void
- This method does not return a value.Use this method to emit events with middleware-based customization, which allows for specific processing +logic or transformations before the event reaches listeners.
+The name of the event to emit.
+Configuration for the event and optional middleware functions.
+Optional
middlewares?: ((event: BaseEventInterface<any>, next: (() => void)) => false | void)[]Returns an array listing the events for which the emitter has registered
listeners. The values in the array are strings or Symbol
s.
import { EventEmitter } from 'node:events';
const myEE = new EventEmitter();
myEE.on('foo', () => {});
myEE.on('bar', () => {});
const sym = Symbol('symbol');
myEE.on(sym, () => {});
console.log(myEE.eventNames());
// Prints: [ 'foo', 'bar', Symbol(symbol) ]
+import { EventEmitter } from 'node:events';
const myEE = new EventEmitter();
myEE.on('foo', () => {});
myEE.on('bar', () => {});
const sym = Symbol('symbol');
myEE.on(sym, () => {});
console.log(myEE.eventNames());
// Prints: [ 'foo', 'bar', Symbol(symbol) ]
getCards
Returns the current state of the deck.
+The array of cards in the deck.
+Returns the current max listener value for the EventEmitter
which is either
set by emitter.setMaxListeners(n)
or defaults to defaultMaxListeners.
Returns the number of listeners listening for the event named eventName
.
+
Returns the number of listeners listening for the event named eventName
.
If listener
is provided, it will return how many times the listener is found
in the list of the listeners of the event.
The name of the event being listened for
Optional
listener: FunctionThe event handler function
Returns a copy of the array of listeners for the event named eventName
.
server.on('connection', (stream) => {
console.log('someone connected!');
});
console.log(util.inspect(server.listeners('connection')));
// Prints: [ [Function] ]
+
Returns a copy of the array of listeners for the event named eventName
.
server.on('connection', (stream) => {
console.log('someone connected!');
});
console.log(util.inspect(server.listeners('connection')));
// Prints: [ [Function] ]
Alias for emitter.removeListener()
.
Alias for emitter.removeListener()
.
Rest
...args: any[]Adds the listener
function to the end of the listeners array for the event
+
Adds the listener
function to the end of the listeners array for the event
named eventName
. No checks are made to see if the listener
has already
been added. Multiple calls passing the same combination of eventName
and
listener
will result in the listener
being added, and called, multiple times.
server.on('connection', (stream) => {
console.log('someone connected!');
});
+server.on('connection', (stream) => {
console.log('someone connected!');
});
Returns a reference to the EventEmitter
, so that calls can be chained.
By default, event listeners are invoked in the order they are added. The emitter.prependListener()
method can be used as an alternative to add the
event listener to the beginning of the listeners array.
-import { EventEmitter } from 'node:events';
const myEE = new EventEmitter();
myEE.on('foo', () => console.log('a'));
myEE.prependListener('foo', () => console.log('b'));
myEE.emit('foo');
// Prints:
// b
// a
+import { EventEmitter } from 'node:events';
const myEE = new EventEmitter();
myEE.on('foo', () => console.log('a'));
myEE.prependListener('foo', () => console.log('b'));
myEE.emit('foo');
// Prints:
// b
// a
The name of the event.
The callback function
Rest
...args: any[]Adds a one-time listener
function for the event named eventName
. The
+
Adds a one-time listener
function for the event named eventName
. The
next time eventName
is triggered, this listener is removed and then invoked.
server.once('connection', (stream) => {
console.log('Ah, we have our first user!');
});
+server.once('connection', (stream) => {
console.log('Ah, we have our first user!');
});
Returns a reference to the EventEmitter
, so that calls can be chained.
By default, event listeners are invoked in the order they are added. The emitter.prependOnceListener()
method can be used as an alternative to add the
event listener to the beginning of the listeners array.
-import { EventEmitter } from 'node:events';
const myEE = new EventEmitter();
myEE.once('foo', () => console.log('a'));
myEE.prependOnceListener('foo', () => console.log('b'));
myEE.emit('foo');
// Prints:
// b
// a
+import { EventEmitter } from 'node:events';
const myEE = new EventEmitter();
myEE.once('foo', () => console.log('a'));
myEE.prependOnceListener('foo', () => console.log('b'));
myEE.emit('foo');
// Prints:
// b
// a
The name of the event.
The callback function
Rest
...args: any[]Adds the listener
function to the beginning of the listeners array for the
+
Adds the listener
function to the beginning of the listeners array for the
event named eventName
. No checks are made to see if the listener
has
already been added. Multiple calls passing the same combination of eventName
and listener
will result in the listener
being added, and called, multiple times.
server.prependListener('connection', (stream) => {
console.log('someone connected!');
});
+server.prependListener('connection', (stream) => {
console.log('someone connected!');
});
Returns a reference to the EventEmitter
, so that calls can be chained.
The name of the event.
The callback function
Rest
...args: any[]Adds a one-timelistener
function for the event named eventName
to the beginning of the listeners array. The next time eventName
is triggered, this
+
Adds a one-timelistener
function for the event named eventName
to the beginning of the listeners array. The next time eventName
is triggered, this
listener is removed, and then invoked.
server.prependOnceListener('connection', (stream) => {
console.log('Ah, we have our first user!');
});
+server.prependOnceListener('connection', (stream) => {
console.log('Ah, we have our first user!');
});
Returns a reference to the EventEmitter
, so that calls can be chained.
The name of the event.
The callback function
Rest
...args: any[]Returns a copy of the array of listeners for the event named eventName
,
+
Returns a copy of the array of listeners for the event named eventName
,
including any wrappers (such as those created by .once()
).
import { EventEmitter } from 'node:events';
const emitter = new EventEmitter();
emitter.once('log', () => console.log('log once'));
// Returns a new Array with a function `onceWrapper` which has a property
// `listener` which contains the original listener bound above
const listeners = emitter.rawListeners('log');
const logFnWrapper = listeners[0];
// Logs "log once" to the console and does not unbind the `once` event
logFnWrapper.listener();
// Logs "log once" to the console and removes the listener
logFnWrapper();
emitter.on('log', () => console.log('log persistently'));
// Will return a new Array with a single function bound by `.on()` above
const newListeners = emitter.rawListeners('log');
// Logs "log persistently" twice
newListeners[0]();
emitter.emit('log');
+import { EventEmitter } from 'node:events';
const emitter = new EventEmitter();
emitter.once('log', () => console.log('log once'));
// Returns a new Array with a function `onceWrapper` which has a property
// `listener` which contains the original listener bound above
const listeners = emitter.rawListeners('log');
const logFnWrapper = listeners[0];
// Logs "log once" to the console and does not unbind the `once` event
logFnWrapper.listener();
// Logs "log once" to the console and removes the listener
logFnWrapper();
emitter.on('log', () => console.log('log persistently'));
// Will return a new Array with a single function bound by `.on()` above
const newListeners = emitter.rawListeners('log');
// Logs "log persistently" twice
newListeners[0]();
emitter.emit('log');
Removes all listeners, or those of the specified eventName
.
It is bad practice to remove listeners added elsewhere in the code,
particularly when the EventEmitter
instance was created by some other
component or module (e.g. sockets or file streams).
Returns a reference to the EventEmitter
, so that calls can be chained.
Optional
eventName: string | symbolRemoves the specified listener
from the listener array for the event named eventName
.
const callback = (stream) => {
console.log('someone connected!');
};
server.on('connection', callback);
// ...
server.removeListener('connection', callback);
+
Removes the specified listener
from the listener array for the event named eventName
.
const callback = (stream) => {
console.log('someone connected!');
};
server.on('connection', callback);
// ...
server.removeListener('connection', callback);
removeListener()
will remove, at most, one instance of a listener from the
@@ -186,7 +228,7 @@
Once an event is emitted, all listeners attached to it at the
time of emitting are called in order. This implies that any removeListener()
or removeAllListeners()
calls after emitting and before the last listener finishes execution
will not remove them fromemit()
in progress. Subsequent events behave as expected.
import { EventEmitter } from 'node:events';
class MyEmitter extends EventEmitter {}
const myEmitter = new MyEmitter();
const callbackA = () => {
console.log('A');
myEmitter.removeListener('event', callbackB);
};
const callbackB = () => {
console.log('B');
};
myEmitter.on('event', callbackA);
myEmitter.on('event', callbackB);
// callbackA removes listener callbackB but it will still be called.
// Internal listener array at time of emit [callbackA, callbackB]
myEmitter.emit('event');
// Prints:
// A
// B
// callbackB is now removed.
// Internal listener array [callbackA]
myEmitter.emit('event');
// Prints:
// A
+import { EventEmitter } from 'node:events';
class MyEmitter extends EventEmitter {}
const myEmitter = new MyEmitter();
const callbackA = () => {
console.log('A');
myEmitter.removeListener('event', callbackB);
};
const callbackB = () => {
console.log('B');
};
myEmitter.on('event', callbackA);
myEmitter.on('event', callbackB);
// callbackA removes listener callbackB but it will still be called.
// Internal listener array at time of emit [callbackA, callbackB]
myEmitter.emit('event');
// Prints:
// A
// B
// callbackB is now removed.
// Internal listener array [callbackA]
myEmitter.emit('event');
// Prints:
// A
Because listeners are managed using an internal array, calling this will
@@ -197,24 +239,24 @@
When a single function has been added as a handler multiple times for a single
event (as in the example below), removeListener()
will remove the most
recently added instance. In the example the once('ping')
listener is removed:
-import { EventEmitter } from 'node:events';
const ee = new EventEmitter();
function pong() {
console.log('pong');
}
ee.on('ping', pong);
ee.once('ping', pong);
ee.removeListener('ping', pong);
ee.emit('ping');
ee.emit('ping');
+import { EventEmitter } from 'node:events';
const ee = new EventEmitter();
function pong() {
console.log('pong');
}
ee.on('ping', pong);
ee.once('ping', pong);
ee.removeListener('ping', pong);
ee.emit('ping');
ee.emit('ping');
Returns a reference to the EventEmitter
, so that calls can be chained.
Rest
...args: any[]By default EventEmitter
s will print a warning if more than 10
listeners are
added for a particular event. This is a useful default that helps finding
memory leaks. The emitter.setMaxListeners()
method allows the limit to be
modified for this specific EventEmitter
instance. The value can be set to Infinity
(or 0
) to indicate an unlimited number of listeners.
Returns a reference to the EventEmitter
, so that calls can be chained.
Static
addStatic
addExperimental
Listens once to the abort
event on the provided signal
.
Listening to the abort
event on abort signals is unsafe and may
lead to resource leaks since another third party with the signal can
call e.stopImmediatePropagation()
. Unfortunately Node.js cannot change
@@ -224,39 +266,39 @@
two issues by listening to the event such that stopImmediatePropagation
does
not prevent the listener from running.
Returns a disposable so that it may be unsubscribed from more easily.
-import { addAbortListener } from 'node:events';
function example(signal) {
let disposable;
try {
signal.addEventListener('abort', (e) => e.stopImmediatePropagation());
disposable = addAbortListener(signal, (e) => {
// Do something when signal is aborted.
});
} finally {
disposable?.[Symbol.dispose]();
}
}
+import { addAbortListener } from 'node:events';
function example(signal) {
let disposable;
try {
signal.addEventListener('abort', (e) => e.stopImmediatePropagation());
disposable = addAbortListener(signal, (e) => {
// Do something when signal is aborted.
});
} finally {
disposable?.[Symbol.dispose]();
}
}
Disposable that removes the abort
listener.
Static
getStatic
getReturns a copy of the array of listeners for the event named eventName
.
For EventEmitter
s this behaves exactly the same as calling .listeners
on
the emitter.
For EventTarget
s this is the only way to get the event listeners for the
event target. This is useful for debugging and diagnostic purposes.
import { getEventListeners, EventEmitter } from 'node:events';
{
const ee = new EventEmitter();
const listener = () => console.log('Events are fun');
ee.on('foo', listener);
console.log(getEventListeners(ee, 'foo')); // [ [Function: listener] ]
}
{
const et = new EventTarget();
const listener = () => console.log('Events are fun');
et.addEventListener('foo', listener);
console.log(getEventListeners(et, 'foo')); // [ [Function: listener] ]
}
+import { getEventListeners, EventEmitter } from 'node:events';
{
const ee = new EventEmitter();
const listener = () => console.log('Events are fun');
ee.on('foo', listener);
console.log(getEventListeners(ee, 'foo')); // [ [Function: listener] ]
}
{
const et = new EventTarget();
const listener = () => console.log('Events are fun');
et.addEventListener('foo', listener);
console.log(getEventListeners(et, 'foo')); // [ [Function: listener] ]
}
Static
getStatic
getReturns the currently set max amount of listeners.
For EventEmitter
s this behaves exactly the same as calling .getMaxListeners
on
the emitter.
For EventTarget
s this is the only way to get the max event listeners for the
event target. If the number of event handlers on a single EventTarget exceeds
the max set, the EventTarget will print a warning.
import { getMaxListeners, setMaxListeners, EventEmitter } from 'node:events';
{
const ee = new EventEmitter();
console.log(getMaxListeners(ee)); // 10
setMaxListeners(11, ee);
console.log(getMaxListeners(ee)); // 11
}
{
const et = new EventTarget();
console.log(getMaxListeners(et)); // 10
setMaxListeners(11, et);
console.log(getMaxListeners(et)); // 11
}
+import { getMaxListeners, setMaxListeners, EventEmitter } from 'node:events';
{
const ee = new EventEmitter();
console.log(getMaxListeners(ee)); // 10
setMaxListeners(11, ee);
console.log(getMaxListeners(ee)); // 11
}
{
const et = new EventTarget();
console.log(getMaxListeners(et)); // 10
setMaxListeners(11, et);
console.log(getMaxListeners(et)); // 11
}
Static
listenerA class method that returns the number of listeners for the given eventName
registered on the given emitter
.
import { EventEmitter, listenerCount } from 'node:events';
const myEmitter = new EventEmitter();
myEmitter.on('event', () => {});
myEmitter.on('event', () => {});
console.log(listenerCount(myEmitter, 'event'));
// Prints: 2
+
Static
listenerA class method that returns the number of listeners for the given eventName
registered on the given emitter
.
import { EventEmitter, listenerCount } from 'node:events';
const myEmitter = new EventEmitter();
myEmitter.on('event', () => {});
myEmitter.on('event', () => {});
console.log(listenerCount(myEmitter, 'event'));
// Prints: 2
The emitter to query
The event name
Static
onimport { on, EventEmitter } from 'node:events';
import process from 'node:process';
const ee = new EventEmitter();
// Emit later on
process.nextTick(() => {
ee.emit('foo', 'bar');
ee.emit('foo', 42);
});
for await (const event of on(ee, 'foo')) {
// The execution of this inner block is synchronous and it
// processes one event at a time (even with await). Do not use
// if concurrent execution is required.
console.log(event); // prints ['bar'] [42]
}
// Unreachable here
+
Static
onimport { on, EventEmitter } from 'node:events';
import process from 'node:process';
const ee = new EventEmitter();
// Emit later on
process.nextTick(() => {
ee.emit('foo', 'bar');
ee.emit('foo', 42);
});
for await (const event of on(ee, 'foo')) {
// The execution of this inner block is synchronous and it
// processes one event at a time (even with await). Do not use
// if concurrent execution is required.
console.log(event); // prints ['bar'] [42]
}
// Unreachable here
Returns an AsyncIterator
that iterates eventName
events. It will throw
@@ -264,40 +306,40 @@
exiting the loop. The value
returned by each iteration is an array
composed of the emitted event arguments.
An AbortSignal
can be used to cancel waiting on events:
import { on, EventEmitter } from 'node:events';
import process from 'node:process';
const ac = new AbortController();
(async () => {
const ee = new EventEmitter();
// Emit later on
process.nextTick(() => {
ee.emit('foo', 'bar');
ee.emit('foo', 42);
});
for await (const event of on(ee, 'foo', { signal: ac.signal })) {
// The execution of this inner block is synchronous and it
// processes one event at a time (even with await). Do not use
// if concurrent execution is required.
console.log(event); // prints ['bar'] [42]
}
// Unreachable here
})();
process.nextTick(() => ac.abort());
+import { on, EventEmitter } from 'node:events';
import process from 'node:process';
const ac = new AbortController();
(async () => {
const ee = new EventEmitter();
// Emit later on
process.nextTick(() => {
ee.emit('foo', 'bar');
ee.emit('foo', 42);
});
for await (const event of on(ee, 'foo', { signal: ac.signal })) {
// The execution of this inner block is synchronous and it
// processes one event at a time (even with await). Do not use
// if concurrent execution is required.
console.log(event); // prints ['bar'] [42]
}
// Unreachable here
})();
process.nextTick(() => ac.abort());
Use the close
option to specify an array of event names that will end the iteration:
-import { on, EventEmitter } from 'node:events';
import process from 'node:process';
const ee = new EventEmitter();
// Emit later on
process.nextTick(() => {
ee.emit('foo', 'bar');
ee.emit('foo', 42);
ee.emit('close');
});
for await (const event of on(ee, 'foo', { close: ['close'] })) {
console.log(event); // prints ['bar'] [42]
}
// the loop will exit after 'close' is emitted
console.log('done'); // prints 'done'
+import { on, EventEmitter } from 'node:events';
import process from 'node:process';
const ee = new EventEmitter();
// Emit later on
process.nextTick(() => {
ee.emit('foo', 'bar');
ee.emit('foo', 42);
ee.emit('close');
});
for await (const event of on(ee, 'foo', { close: ['close'] })) {
console.log(event); // prints ['bar'] [42]
}
// the loop will exit after 'close' is emitted
console.log('done'); // prints 'done'
Optional
options: StaticEventEmitterIteratorOptionsAn AsyncIterator
that iterates eventName
events emitted by the emitter
Optional
options: StaticEventEmitterIteratorOptionsStatic
onceCreates a Promise
that is fulfilled when the EventEmitter
emits the given
+
Optional
options: StaticEventEmitterIteratorOptionsStatic
onceCreates a Promise
that is fulfilled when the EventEmitter
emits the given
event or that is rejected if the EventEmitter
emits 'error'
while waiting.
The Promise
will resolve with an array of all the arguments emitted to the
given event.
This method is intentionally generic and works with the web platform EventTarget interface, which has no special'error'
event
semantics and does not listen to the 'error'
event.
import { once, EventEmitter } from 'node:events';
import process from 'node:process';
const ee = new EventEmitter();
process.nextTick(() => {
ee.emit('myevent', 42);
});
const [value] = await once(ee, 'myevent');
console.log(value);
const err = new Error('kaboom');
process.nextTick(() => {
ee.emit('error', err);
});
try {
await once(ee, 'myevent');
} catch (err) {
console.error('error happened', err);
}
+import { once, EventEmitter } from 'node:events';
import process from 'node:process';
const ee = new EventEmitter();
process.nextTick(() => {
ee.emit('myevent', 42);
});
const [value] = await once(ee, 'myevent');
console.log(value);
const err = new Error('kaboom');
process.nextTick(() => {
ee.emit('error', err);
});
try {
await once(ee, 'myevent');
} catch (err) {
console.error('error happened', err);
}
The special handling of the 'error'
event is only used when events.once()
is used to wait for another event. If events.once()
is used to wait for the
'error'
event itself, then it is treated as any other kind of event without
special handling:
-import { EventEmitter, once } from 'node:events';
const ee = new EventEmitter();
once(ee, 'error')
.then(([err]) => console.log('ok', err.message))
.catch((err) => console.error('error', err.message));
ee.emit('error', new Error('boom'));
// Prints: ok boom
+import { EventEmitter, once } from 'node:events';
const ee = new EventEmitter();
once(ee, 'error')
.then(([err]) => console.log('ok', err.message))
.catch((err) => console.error('error', err.message));
ee.emit('error', new Error('boom'));
// Prints: ok boom
An AbortSignal
can be used to cancel waiting for the event:
-import { EventEmitter, once } from 'node:events';
const ee = new EventEmitter();
const ac = new AbortController();
async function foo(emitter, event, signal) {
try {
await once(emitter, event, { signal });
console.log('event emitted!');
} catch (error) {
if (error.name === 'AbortError') {
console.error('Waiting for the event was canceled!');
} else {
console.error('There was an error', error.message);
}
}
}
foo(ee, 'foo', ac.signal);
ac.abort(); // Abort waiting for the event
ee.emit('foo'); // Prints: Waiting for the event was canceled!
+import { EventEmitter, once } from 'node:events';
const ee = new EventEmitter();
const ac = new AbortController();
async function foo(emitter, event, signal) {
try {
await once(emitter, event, { signal });
console.log('event emitted!');
} catch (error) {
if (error.name === 'AbortError') {
console.error('Waiting for the event was canceled!');
} else {
console.error('There was an error', error.message);
}
}
}
foo(ee, 'foo', ac.signal);
ac.abort(); // Abort waiting for the event
ee.emit('foo'); // Prints: Waiting for the event was canceled!
Optional
options: StaticEventEmitterOptionsOptional
options: StaticEventEmitterOptionsStatic
setimport { setMaxListeners, EventEmitter } from 'node:events';
const target = new EventTarget();
const emitter = new EventEmitter();
setMaxListeners(5, target, emitter);
+
Optional
options: StaticEventEmitterOptionsStatic
setimport { setMaxListeners, EventEmitter } from 'node:events';
const target = new EventTarget();
const emitter = new EventEmitter();
setMaxListeners(5, target, emitter);
Optional
n: numberA non-negative number. The maximum number of listeners per EventTarget
event.
Rest
...eventTargets: (EventEmitter<DefaultEventMap> | EventTarget)[]Zero or more {EventTarget} or {EventEmitter} instances. If none are specified, n
is set as the default max for all newly created {EventTarget} and {EventEmitter}
objects.
Logger
Provides logging functionality for the library, supporting both file-based and console logging. This class +allows configurable logging levels and environment-specific log directories for flexible and organized logging.
+The Logger
class is designed to capture and store logs with various severity levels. It centralizes
+logging within the library, ensuring that messages are consistently recorded and easily accessible for
+debugging, monitoring, and auditing purposes.
Implements LoggerInterface
, adhering to standardized log methods and configuration options.
The Logger
class includes the following methods:
log(level: LogLevel, message: string, data?: Record<string, any>): Promise<void>
: Logs a message with a specified level and optional data context.initializeLogDirectory()
: Initializes the log directory structure if it does not exist.setupLogDirPath(basePath: string): string
: Configures the base path for log files, adding environment-specific subdirectories.__writeLogToFile(level: LogLevel, message: string): Promise<void>
: Writes a formatted log message to a file based on the log level and date.Instantiate the Logger
with a configuration to customize logging behavior, including specifying the log
+directory path and enabling console output. Once instantiated, use the log
method to record messages
+with various levels, which are stored in both files and optionally displayed in the console.
Initializes a new instance of the Logger
class with optional configuration settings.
This constructor configures the Logger
class by initializing settings such as the log directory path,
+console logging preferences, and environment setup.
config?: LoggerConfig
- Optional. A configuration object for log directory path and console logging settings.
+logDirPath: string
- Specifies the base directory for log files. Defaults to ./logs
if not provided.enableConsoleLogging: boolean
- Determines if logs should also appear in the console. Defaults to true
.void
- The constructor does not return a value.Instantiates the Logger
with custom configurations, which dictate logging behavior across the library.
Optional
config: LoggerConfigOptional. Configuration for log directory path and console logging settings.
+The disableConsoleLogging
method disables console logging for the Logger
instance. When disabled, log
+entries are only written to log files and are no longer displayed in the console.
This method provides a way to turn off console output of log messages, which is useful for reducing console +clutter in production environments where log messages are typically directed only to log files.
+N/A
+N/A
+N/A
+boolean
- Returns false
indicating console logging is now disabled.Use this method to disable console logging, especially in production environments where log messages +should only be stored in log files.
+false
indicating that console logging is disabled.The enableConsoleLogging
method enables console logging for the Logger
instance. When activated, all log
+entries are displayed in the console in addition to being recorded in log files.
This method provides a way to turn on real-time logging output to the console, which is particularly useful +for development and debugging purposes, allowing for immediate feedback on logged events.
+N/A
+N/A
+N/A
+boolean
- Returns true
indicating console logging is now enabled.Use this method to enable console logging for quick visibility of log messages during debugging or development.
+true
indicating that console logging is enabled.Retrieves the current status of console logging, indicating if logs are also output to the console.
+This getter provides access to the console logging status, useful for checking if real-time log output is enabled.
+N/A
+boolean
- true
if console logging is enabled, false
otherwise.This method is used to verify whether logs are configured to appear in the console.
+Retrieves the environment setting currently configured in the Logger instance, such as "development"
or "production"
.
This getter method allows access to the environment setting, which determines where logs are stored based on runtime context.
+N/A
+string
- The environment setting in use.Use this method to check the runtime environment configured for the Logger.
+"development"
).Retrieves the path of the directory where logs are stored, based on the Logger's configuration and environment setting.
+This method allows access to the path where logs are written, organized by environment. Useful for managing and verifying log storage locations.
+N/A
+string
- The full directory path for log storage.This method is used to determine where logs are stored on the filesystem, ensuring accessibility and organization.
+The log
method logs a message at a specified severity level with optional data. It supports both console
+output and file-based logging, structuring logs based on environment and log level.
This method serves as the core logging function, allowing consistent recording of messages across the library. +By accepting a log level and optional data, it provides detailed logging for events, errors, or informational messages.
+Implements the logging functionality from the LoggerInterface
.
N/A
+level: LogLevel
- The log's severity level, which determines where it appears. Valid options include:
+LogLevel.INFO
: Informational messages indicating standard operations.LogLevel.WARN
: Warnings that indicate potential issues.LogLevel.ERROR
: Critical errors requiring attention.message: string
- The primary log message, ideally concise and descriptive.data?: Record<string, any>
- Optional. Additional data to provide context, such as error codes or debug info.level
must be a recognized value in LogLevel
.message
should clearly describe the log's purpose, providing insight into system operations.Promise<void>
- Resolves when the log entry is recorded, either in the console or file.Use this method to log critical information across the library, choosing the appropriate LogLevel
to match
+the importance and visibility requirements of the message.
The log's severity level.
+The main log message.
+Optional
data: Record<string, any>Optional additional data for context.
+Static
getProvides access to the singleton instance of the Logger
class. This method ensures that only one instance of
+the logger is created and shared across the application, providing a centralized logging management system.
+It initializes the logger with a configuration if not already initialized.
The getInstance
method enforces the Singleton pattern, ensuring that a single instance of the logger is used
+across the entire library or application. This approach helps maintain consistency in logging configuration,
+making sure that all logs are handled by a single, globally accessible instance.
N/A
+N/A
+N/A
+config?: LoggerConfig
- An optional configuration object for customizing the logger instance:
+logDirPath: string
- Optional. Specifies the directory path for storing log files. Defaults to a standard location if omitted.enableConsoleLogging: boolean
- Optional. Enables or disables logging to the console. Defaults to true
if omitted.getInstance
+ignore additional configurations.Logger
- Returns the singleton instance of the Logger
class, ensuring that the same instance is shared
+throughout the application.Use this method to retrieve the Logger
instance wherever logging is required. This method guarantees that the
+same instance of the Logger
is used, maintaining a consistent logging configuration.
Optional
config: LoggerConfigConfiguration options for the logger instance.
+Logger
.// Initialize and retrieve the Logger instance with configuration
const logger = Logger.getInstance({ logDirPath: "./logs", enableConsoleLogging: true });
logger.log(LogLevel.INFO, "Application started"); // Logs with the singleton logger instance
// Retrieve the existing Logger instance without reinitializing
const anotherLoggerReference = Logger.getInstance();
anotherLoggerReference.log(LogLevel.ERROR, "Unexpected error occurred");
// Both `logger` and `anotherLoggerReference` refer to the same Logger instance
+
+
+PokerGame
+Represents the current PokerGame being played at the PokerTable.
+Manages the deck, community cards, and game phases, such as pre-flop, flop, turn, and river.
constructor
+Creates an instance of a Deck with 52 cards. +Automatically initializes the deck with all combinations of ranks and suits.
+Optional
config: PokerGameConfigStatic
captureValue: boolean
+Change the default captureRejections
option on all new EventEmitter
objects.
Static
Readonly
captureValue: Symbol.for('nodejs.rejection')
See how to write a custom rejection handler
.
Static
defaultBy default, a maximum of 10
listeners can be registered for any single
+event. This limit can be changed for individual EventEmitter
instances
+using the emitter.setMaxListeners(n)
method. To change the default
+for allEventEmitter
instances, the events.defaultMaxListeners
property
+can be used. If this value is not a positive number, a RangeError
is thrown.
Take caution when setting the events.defaultMaxListeners
because the
+change affects all EventEmitter
instances, including those created before
+the change is made. However, calling emitter.setMaxListeners(n)
still has
+precedence over events.defaultMaxListeners
.
This is not a hard limit. The EventEmitter
instance will allow
+more listeners to be added but will output a trace warning to stderr indicating
+that a "possible EventEmitter memory leak" has been detected. For any single
+EventEmitter
, the emitter.getMaxListeners()
and emitter.setMaxListeners()
methods can be used to
+temporarily avoid this warning:
import { EventEmitter } from 'node:events';
const emitter = new EventEmitter();
emitter.setMaxListeners(emitter.getMaxListeners() + 1);
emitter.once('event', () => {
// do stuff
emitter.setMaxListeners(Math.max(emitter.getMaxListeners() - 1, 0));
});
+
+
+The --trace-warnings
command-line flag can be used to display the
+stack trace for such warnings.
The emitted warning can be inspected with process.on('warning')
and will
+have the additional emitter
, type
, and count
properties, referring to
+the event emitter instance, the event's name and the number of attached
+listeners, respectively.
+Its name
property is set to 'MaxListenersExceededWarning'
.
Static
Readonly
errorThis symbol shall be used to install a listener for only monitoring 'error'
events. Listeners installed using this symbol are called before the regular 'error'
listeners are called.
Installing a listener using this symbol does not change the behavior once an 'error'
event is emitted. Therefore, the process will still crash if no
+regular 'error'
listener is installed.
Optional
[captureRest
...args: AnyRestAlias for emitter.on(eventName, listener)
.
Rest
...args: any[]Synchronously calls each of the listeners registered for the event named eventName
, in the order they were registered, passing the supplied arguments
+to each.
Returns true
if the event had listeners, false
otherwise.
import { EventEmitter } from 'node:events';
const myEmitter = new EventEmitter();
// First listener
myEmitter.on('event', function firstListener() {
console.log('Helloooo! first listener');
});
// Second listener
myEmitter.on('event', function secondListener(arg1, arg2) {
console.log(`event with parameters ${arg1}, ${arg2} in second listener`);
});
// Third listener
myEmitter.on('event', function thirdListener(...args) {
const parameters = args.join(', ');
console.log(`event with parameters ${parameters} in third listener`);
});
console.log(myEmitter.listeners('event'));
myEmitter.emit('event', 1, 2, 3, 4, 5);
// Prints:
// [
// [Function: firstListener],
// [Function: secondListener],
// [Function: thirdListener]
// ]
// Helloooo! first listener
// event with parameters 1, 2 in second listener
// event with parameters 1, 2, 3, 4, 5 in third listener
+
+
+Rest
...args: AnyRestThe emitEvent
method is a public method for emitting events, with an optional configuration that allows
+middleware processing. Middleware functions can intercept and transform the event before it reaches the listeners,
+allowing custom validation or data modifications.
This method enables flexible event emission with support for middleware, providing a robust event processing
+mechanism in the BaseEventEmitter
. It’s useful for customizing event behavior based on application-specific needs.
N/A
+N/A
+This method can emit any event specified by eventName
, which can then be processed by middleware functions if defined.
eventName: string
- The name of the event to emit.options: { event: { data: { [key: string]: any }; [key: string]: any; }, middlewares?: Array<(event: BaseEventInterface, next: () => void) => void | false> }
+eventName
must be a valid string.options.event
should include relevant data for the event. If middlewares
are provided, they should be functions with an event and next parameter.void
- This method does not return a value.Use this method to emit events with middleware-based customization, which allows for specific processing +logic or transformations before the event reaches listeners.
+The name of the event to emit.
+Configuration for the event and optional middleware functions.
+Optional
middlewares?: ((event: BaseEventInterface<any>, next: (() => void)) => false | void)[]Returns an array listing the events for which the emitter has registered
+listeners. The values in the array are strings or Symbol
s.
import { EventEmitter } from 'node:events';
const myEE = new EventEmitter();
myEE.on('foo', () => {});
myEE.on('bar', () => {});
const sym = Symbol('symbol');
myEE.on(sym, () => {});
console.log(myEE.eventNames());
// Prints: [ 'foo', 'bar', Symbol(symbol) ]
+
+
+Returns the current max listener value for the EventEmitter
which is either
+set by emitter.setMaxListeners(n)
or defaults to defaultMaxListeners.
READ METHODS (GETTERS & DATA RETRIEVAL)
+Returns the number of listeners listening for the event named eventName
.
+If listener
is provided, it will return how many times the listener is found
+in the list of the listeners of the event.
The name of the event being listened for
+Optional
listener: FunctionThe event handler function
+Returns a copy of the array of listeners for the event named eventName
.
server.on('connection', (stream) => {
console.log('someone connected!');
});
console.log(util.inspect(server.listeners('connection')));
// Prints: [ [Function] ]
+
+
+Alias for emitter.removeListener()
.
Rest
...args: any[]Adds the listener
function to the end of the listeners array for the event
+named eventName
. No checks are made to see if the listener
has already
+been added. Multiple calls passing the same combination of eventName
and
+listener
will result in the listener
being added, and called, multiple times.
server.on('connection', (stream) => {
console.log('someone connected!');
});
+
+
+Returns a reference to the EventEmitter
, so that calls can be chained.
By default, event listeners are invoked in the order they are added. The emitter.prependListener()
method can be used as an alternative to add the
+event listener to the beginning of the listeners array.
import { EventEmitter } from 'node:events';
const myEE = new EventEmitter();
myEE.on('foo', () => console.log('a'));
myEE.prependListener('foo', () => console.log('b'));
myEE.emit('foo');
// Prints:
// b
// a
+
+
+The name of the event.
+The callback function
+Rest
...args: any[]Adds a one-time listener
function for the event named eventName
. The
+next time eventName
is triggered, this listener is removed and then invoked.
server.once('connection', (stream) => {
console.log('Ah, we have our first user!');
});
+
+
+Returns a reference to the EventEmitter
, so that calls can be chained.
By default, event listeners are invoked in the order they are added. The emitter.prependOnceListener()
method can be used as an alternative to add the
+event listener to the beginning of the listeners array.
import { EventEmitter } from 'node:events';
const myEE = new EventEmitter();
myEE.once('foo', () => console.log('a'));
myEE.prependOnceListener('foo', () => console.log('b'));
myEE.emit('foo');
// Prints:
// b
// a
+
+
+The name of the event.
+The callback function
+Rest
...args: any[]Adds the listener
function to the beginning of the listeners array for the
+event named eventName
. No checks are made to see if the listener
has
+already been added. Multiple calls passing the same combination of eventName
+and listener
will result in the listener
being added, and called, multiple times.
server.prependListener('connection', (stream) => {
console.log('someone connected!');
});
+
+
+Returns a reference to the EventEmitter
, so that calls can be chained.
The name of the event.
+The callback function
+Rest
...args: any[]Adds a one-timelistener
function for the event named eventName
to the beginning of the listeners array. The next time eventName
is triggered, this
+listener is removed, and then invoked.
server.prependOnceListener('connection', (stream) => {
console.log('Ah, we have our first user!');
});
+
+
+Returns a reference to the EventEmitter
, so that calls can be chained.
The name of the event.
+The callback function
+Rest
...args: any[]Returns a copy of the array of listeners for the event named eventName
,
+including any wrappers (such as those created by .once()
).
import { EventEmitter } from 'node:events';
const emitter = new EventEmitter();
emitter.once('log', () => console.log('log once'));
// Returns a new Array with a function `onceWrapper` which has a property
// `listener` which contains the original listener bound above
const listeners = emitter.rawListeners('log');
const logFnWrapper = listeners[0];
// Logs "log once" to the console and does not unbind the `once` event
logFnWrapper.listener();
// Logs "log once" to the console and removes the listener
logFnWrapper();
emitter.on('log', () => console.log('log persistently'));
// Will return a new Array with a single function bound by `.on()` above
const newListeners = emitter.rawListeners('log');
// Logs "log persistently" twice
newListeners[0]();
emitter.emit('log');
+
+
+Removes all listeners, or those of the specified eventName
.
It is bad practice to remove listeners added elsewhere in the code,
+particularly when the EventEmitter
instance was created by some other
+component or module (e.g. sockets or file streams).
Returns a reference to the EventEmitter
, so that calls can be chained.
Optional
eventName: string | symbolRemoves the specified listener
from the listener array for the event named eventName
.
const callback = (stream) => {
console.log('someone connected!');
};
server.on('connection', callback);
// ...
server.removeListener('connection', callback);
+
+
+removeListener()
will remove, at most, one instance of a listener from the
+listener array. If any single listener has been added multiple times to the
+listener array for the specified eventName
, then removeListener()
must be
+called multiple times to remove each instance.
Once an event is emitted, all listeners attached to it at the
+time of emitting are called in order. This implies that any removeListener()
or removeAllListeners()
calls after emitting and before the last listener finishes execution
+will not remove them fromemit()
in progress. Subsequent events behave as expected.
import { EventEmitter } from 'node:events';
class MyEmitter extends EventEmitter {}
const myEmitter = new MyEmitter();
const callbackA = () => {
console.log('A');
myEmitter.removeListener('event', callbackB);
};
const callbackB = () => {
console.log('B');
};
myEmitter.on('event', callbackA);
myEmitter.on('event', callbackB);
// callbackA removes listener callbackB but it will still be called.
// Internal listener array at time of emit [callbackA, callbackB]
myEmitter.emit('event');
// Prints:
// A
// B
// callbackB is now removed.
// Internal listener array [callbackA]
myEmitter.emit('event');
// Prints:
// A
+
+
+Because listeners are managed using an internal array, calling this will
+change the position indices of any listener registered after the listener
+being removed. This will not impact the order in which listeners are called,
+but it means that any copies of the listener array as returned by
+the emitter.listeners()
method will need to be recreated.
When a single function has been added as a handler multiple times for a single
+event (as in the example below), removeListener()
will remove the most
+recently added instance. In the example the once('ping')
listener is removed:
import { EventEmitter } from 'node:events';
const ee = new EventEmitter();
function pong() {
console.log('pong');
}
ee.on('ping', pong);
ee.once('ping', pong);
ee.removeListener('ping', pong);
ee.emit('ping');
ee.emit('ping');
+
+
+Returns a reference to the EventEmitter
, so that calls can be chained.
Rest
...args: any[]By default EventEmitter
s will print a warning if more than 10
listeners are
+added for a particular event. This is a useful default that helps finding
+memory leaks. The emitter.setMaxListeners()
method allows the limit to be
+modified for this specific EventEmitter
instance. The value can be set to Infinity
(or 0
) to indicate an unlimited number of listeners.
Returns a reference to the EventEmitter
, so that calls can be chained.
Static
addExperimental
Listens once to the abort
event on the provided signal
.
Listening to the abort
event on abort signals is unsafe and may
+lead to resource leaks since another third party with the signal can
+call e.stopImmediatePropagation()
. Unfortunately Node.js cannot change
+this since it would violate the web standard. Additionally, the original
+API makes it easy to forget to remove listeners.
This API allows safely using AbortSignal
s in Node.js APIs by solving these
+two issues by listening to the event such that stopImmediatePropagation
does
+not prevent the listener from running.
Returns a disposable so that it may be unsubscribed from more easily.
+import { addAbortListener } from 'node:events';
function example(signal) {
let disposable;
try {
signal.addEventListener('abort', (e) => e.stopImmediatePropagation());
disposable = addAbortListener(signal, (e) => {
// Do something when signal is aborted.
});
} finally {
disposable?.[Symbol.dispose]();
}
}
+
+
+Disposable that removes the abort
listener.
Static
getReturns a copy of the array of listeners for the event named eventName
.
For EventEmitter
s this behaves exactly the same as calling .listeners
on
+the emitter.
For EventTarget
s this is the only way to get the event listeners for the
+event target. This is useful for debugging and diagnostic purposes.
import { getEventListeners, EventEmitter } from 'node:events';
{
const ee = new EventEmitter();
const listener = () => console.log('Events are fun');
ee.on('foo', listener);
console.log(getEventListeners(ee, 'foo')); // [ [Function: listener] ]
}
{
const et = new EventTarget();
const listener = () => console.log('Events are fun');
et.addEventListener('foo', listener);
console.log(getEventListeners(et, 'foo')); // [ [Function: listener] ]
}
+
+
+Static
getReturns the currently set max amount of listeners.
+For EventEmitter
s this behaves exactly the same as calling .getMaxListeners
on
+the emitter.
For EventTarget
s this is the only way to get the max event listeners for the
+event target. If the number of event handlers on a single EventTarget exceeds
+the max set, the EventTarget will print a warning.
import { getMaxListeners, setMaxListeners, EventEmitter } from 'node:events';
{
const ee = new EventEmitter();
console.log(getMaxListeners(ee)); // 10
setMaxListeners(11, ee);
console.log(getMaxListeners(ee)); // 11
}
{
const et = new EventTarget();
console.log(getMaxListeners(et)); // 10
setMaxListeners(11, et);
console.log(getMaxListeners(et)); // 11
}
+
+
+Static
listenerA class method that returns the number of listeners for the given eventName
registered on the given emitter
.
import { EventEmitter, listenerCount } from 'node:events';
const myEmitter = new EventEmitter();
myEmitter.on('event', () => {});
myEmitter.on('event', () => {});
console.log(listenerCount(myEmitter, 'event'));
// Prints: 2
+
+
+The emitter to query
+The event name
+Static
onimport { on, EventEmitter } from 'node:events';
import process from 'node:process';
const ee = new EventEmitter();
// Emit later on
process.nextTick(() => {
ee.emit('foo', 'bar');
ee.emit('foo', 42);
});
for await (const event of on(ee, 'foo')) {
// The execution of this inner block is synchronous and it
// processes one event at a time (even with await). Do not use
// if concurrent execution is required.
console.log(event); // prints ['bar'] [42]
}
// Unreachable here
+
+
+Returns an AsyncIterator
that iterates eventName
events. It will throw
+if the EventEmitter
emits 'error'
. It removes all listeners when
+exiting the loop. The value
returned by each iteration is an array
+composed of the emitted event arguments.
An AbortSignal
can be used to cancel waiting on events:
import { on, EventEmitter } from 'node:events';
import process from 'node:process';
const ac = new AbortController();
(async () => {
const ee = new EventEmitter();
// Emit later on
process.nextTick(() => {
ee.emit('foo', 'bar');
ee.emit('foo', 42);
});
for await (const event of on(ee, 'foo', { signal: ac.signal })) {
// The execution of this inner block is synchronous and it
// processes one event at a time (even with await). Do not use
// if concurrent execution is required.
console.log(event); // prints ['bar'] [42]
}
// Unreachable here
})();
process.nextTick(() => ac.abort());
+
+
+Use the close
option to specify an array of event names that will end the iteration:
import { on, EventEmitter } from 'node:events';
import process from 'node:process';
const ee = new EventEmitter();
// Emit later on
process.nextTick(() => {
ee.emit('foo', 'bar');
ee.emit('foo', 42);
ee.emit('close');
});
for await (const event of on(ee, 'foo', { close: ['close'] })) {
console.log(event); // prints ['bar'] [42]
}
// the loop will exit after 'close' is emitted
console.log('done'); // prints 'done'
+
+
+Optional
options: StaticEventEmitterIteratorOptionsAn AsyncIterator
that iterates eventName
events emitted by the emitter
Optional
options: StaticEventEmitterIteratorOptionsStatic
onceCreates a Promise
that is fulfilled when the EventEmitter
emits the given
+event or that is rejected if the EventEmitter
emits 'error'
while waiting.
+The Promise
will resolve with an array of all the arguments emitted to the
+given event.
This method is intentionally generic and works with the web platform EventTarget interface, which has no special'error'
event
+semantics and does not listen to the 'error'
event.
import { once, EventEmitter } from 'node:events';
import process from 'node:process';
const ee = new EventEmitter();
process.nextTick(() => {
ee.emit('myevent', 42);
});
const [value] = await once(ee, 'myevent');
console.log(value);
const err = new Error('kaboom');
process.nextTick(() => {
ee.emit('error', err);
});
try {
await once(ee, 'myevent');
} catch (err) {
console.error('error happened', err);
}
+
+
+The special handling of the 'error'
event is only used when events.once()
is used to wait for another event. If events.once()
is used to wait for the
+'error'
event itself, then it is treated as any other kind of event without
+special handling:
import { EventEmitter, once } from 'node:events';
const ee = new EventEmitter();
once(ee, 'error')
.then(([err]) => console.log('ok', err.message))
.catch((err) => console.error('error', err.message));
ee.emit('error', new Error('boom'));
// Prints: ok boom
+
+
+An AbortSignal
can be used to cancel waiting for the event:
import { EventEmitter, once } from 'node:events';
const ee = new EventEmitter();
const ac = new AbortController();
async function foo(emitter, event, signal) {
try {
await once(emitter, event, { signal });
console.log('event emitted!');
} catch (error) {
if (error.name === 'AbortError') {
console.error('Waiting for the event was canceled!');
} else {
console.error('There was an error', error.message);
}
}
}
foo(ee, 'foo', ac.signal);
ac.abort(); // Abort waiting for the event
ee.emit('foo'); // Prints: Waiting for the event was canceled!
+
+
+Optional
options: StaticEventEmitterOptionsOptional
options: StaticEventEmitterOptionsStatic
setimport { setMaxListeners, EventEmitter } from 'node:events';
const target = new EventTarget();
const emitter = new EventEmitter();
setMaxListeners(5, target, emitter);
+
+
+Optional
n: numberA non-negative number. The maximum number of listeners per EventTarget
event.
Rest
...eventTargets: (EventEmitter<DefaultEventMap> | EventTarget)[]Zero or more {EventTarget} or {EventEmitter} instances. If none are specified, n
is set as the default max for all newly created {EventTarget} and {EventEmitter}
+objects.
PokerPhase
Manages the various phases of a poker game, such as "Pre-Flop," "Flop," "Turn," and "River." This class encapsulates +the deck, community cards, and controls to transition between these game phases within a single round of poker.
+The PokerPhase
class standardizes and manages the sequence and actions taken during each phase of a poker game.
+It ensures that the game progresses logically from one phase to another, maintaining the integrity of gameplay by
+enforcing rules specific to each phase and managing the deck and community cards.
BaseEventEmitter
, enabling event-based responses to phase changes and key game events.PokerPhaseInterface
, defining essential methods and properties for managing a poker game phase.constructor
, __initPhase
(sets up the deck and initial phase properties).nextPhase
, resetPhase
.phase:change
- Emitted each time the phase changes, enabling updates to game state.phase:end
- Emitted when the final phase (River) ends, signaling the conclusion of the phase sequence.This class is instantiated and utilized during a poker game to control the progression through each game phase.
+It is designed for integration within a PokerTable
or PokerRoom
, where it serves as the core game phase manager.
constructor
+Initializes a new instance of PokerPhase
with configurable settings for the game round, including players, deck,
+community cards, pot, and player positions (dealer, small blind, big blind).
The constructor sets up the PokerPhase
instance, calling the __init
method to initialize the deck, player settings,
+and positions for the game round. It also emits events for listeners when the phase starts.
config
(optional): A PokerPhaseConfig
object to configure properties like phase name, deck, community cards,
+players, pot, and positional markers.The constructor is used to initialize a PokerPhase
instance with specific configurations, including player information
+and positions for the phase.
Optional
config: PokerPhaseConfigOptional configuration object with properties for setting up the poker phase.
+Static
captureValue: boolean
+Change the default captureRejections
option on all new EventEmitter
objects.
Static
Readonly
captureValue: Symbol.for('nodejs.rejection')
See how to write a custom rejection handler
.
Static
defaultBy default, a maximum of 10
listeners can be registered for any single
+event. This limit can be changed for individual EventEmitter
instances
+using the emitter.setMaxListeners(n)
method. To change the default
+for allEventEmitter
instances, the events.defaultMaxListeners
property
+can be used. If this value is not a positive number, a RangeError
is thrown.
Take caution when setting the events.defaultMaxListeners
because the
+change affects all EventEmitter
instances, including those created before
+the change is made. However, calling emitter.setMaxListeners(n)
still has
+precedence over events.defaultMaxListeners
.
This is not a hard limit. The EventEmitter
instance will allow
+more listeners to be added but will output a trace warning to stderr indicating
+that a "possible EventEmitter memory leak" has been detected. For any single
+EventEmitter
, the emitter.getMaxListeners()
and emitter.setMaxListeners()
methods can be used to
+temporarily avoid this warning:
import { EventEmitter } from 'node:events';
const emitter = new EventEmitter();
emitter.setMaxListeners(emitter.getMaxListeners() + 1);
emitter.once('event', () => {
// do stuff
emitter.setMaxListeners(Math.max(emitter.getMaxListeners() - 1, 0));
});
+
+
+The --trace-warnings
command-line flag can be used to display the
+stack trace for such warnings.
The emitted warning can be inspected with process.on('warning')
and will
+have the additional emitter
, type
, and count
properties, referring to
+the event emitter instance, the event's name and the number of attached
+listeners, respectively.
+Its name
property is set to 'MaxListenersExceededWarning'
.
Static
Readonly
errorThis symbol shall be used to install a listener for only monitoring 'error'
events. Listeners installed using this symbol are called before the regular 'error'
listeners are called.
Installing a listener using this symbol does not change the behavior once an 'error'
event is emitted. Therefore, the process will still crash if no
+regular 'error'
listener is installed.
setName
Returns the poker table's id
.
The poker table's id
.
Protected
_betProtected
_foldOptional
[captureRest
...args: AnyRestAlias for emitter.on(eventName, listener)
.
Rest
...args: any[]Synchronously calls each of the listeners registered for the event named eventName
, in the order they were registered, passing the supplied arguments
+to each.
Returns true
if the event had listeners, false
otherwise.
import { EventEmitter } from 'node:events';
const myEmitter = new EventEmitter();
// First listener
myEmitter.on('event', function firstListener() {
console.log('Helloooo! first listener');
});
// Second listener
myEmitter.on('event', function secondListener(arg1, arg2) {
console.log(`event with parameters ${arg1}, ${arg2} in second listener`);
});
// Third listener
myEmitter.on('event', function thirdListener(...args) {
const parameters = args.join(', ');
console.log(`event with parameters ${parameters} in third listener`);
});
console.log(myEmitter.listeners('event'));
myEmitter.emit('event', 1, 2, 3, 4, 5);
// Prints:
// [
// [Function: firstListener],
// [Function: secondListener],
// [Function: thirdListener]
// ]
// Helloooo! first listener
// event with parameters 1, 2 in second listener
// event with parameters 1, 2, 3, 4, 5 in third listener
+
+
+Rest
...args: AnyRestThe emitEvent
method is a public method for emitting events, with an optional configuration that allows
+middleware processing. Middleware functions can intercept and transform the event before it reaches the listeners,
+allowing custom validation or data modifications.
This method enables flexible event emission with support for middleware, providing a robust event processing
+mechanism in the BaseEventEmitter
. It’s useful for customizing event behavior based on application-specific needs.
N/A
+N/A
+This method can emit any event specified by eventName
, which can then be processed by middleware functions if defined.
eventName: string
- The name of the event to emit.options: { event: { data: { [key: string]: any }; [key: string]: any; }, middlewares?: Array<(event: BaseEventInterface, next: () => void) => void | false> }
+eventName
must be a valid string.options.event
should include relevant data for the event. If middlewares
are provided, they should be functions with an event and next parameter.void
- This method does not return a value.Use this method to emit events with middleware-based customization, which allows for specific processing +logic or transformations before the event reaches listeners.
+The name of the event to emit.
+Configuration for the event and optional middleware functions.
+Optional
middlewares?: ((event: BaseEventInterface<any>, next: (() => void)) => false | void)[]Returns an array listing the events for which the emitter has registered
+listeners. The values in the array are strings or Symbol
s.
import { EventEmitter } from 'node:events';
const myEE = new EventEmitter();
myEE.on('foo', () => {});
myEE.on('bar', () => {});
const sym = Symbol('symbol');
myEE.on(sym, () => {});
console.log(myEE.eventNames());
// Prints: [ 'foo', 'bar', Symbol(symbol) ]
+
+
+Retrieves the position of the player assigned the big blind.
+N/A
+N/A
+Helps identify the player with the big blind, aiding in betting actions.
+N/A
+N/A
+Used to determine the big blind in betting rounds.
+Retrieves the position of the player whose turn it currently is within the PokerPhase
.
N/A
+N/A
+Helps identify the active player during the phase, supporting turn-based actions.
+N/A
+N/A
+Useful in determining which player should act next in the game round.
+Retrieves the dealer's position for the current phase of poker.
+N/A
+N/A
+Indicates which player holds the dealer role, which is essential for turn-based actions.
+N/A
+N/A
+Useful for determining turn order and dealer-related actions.
+Retrieves the deck of cards currently being used in the PokerPhase
.
N/A
+N/A
+Accesses the deck to support game actions involving the deck, such as dealing or shuffling.
+N/A
+N/A
+Useful for accessing the deck when cards need to be drawn or reset.
+Returns the current max listener value for the EventEmitter
which is either
+set by emitter.setMaxListeners(n)
or defaults to defaultMaxListeners.
Retrieves the current phase name (e.g., "Pre-Flop," "Flop") of the PokerPhase
.
N/A
+N/A
+Provides the phase name, helping other parts of the code determine the current stage of the game round.
+N/A
+N/A
+Useful for determining the phase of gameplay, allowing specific actions based on the current phase.
+Retrieves the list of players currently involved in the PokerPhase
.
N/A
+N/A
+Accesses the players participating in the current phase, supporting functions that involve player actions or status.
+N/A
+N/A
+This method is commonly used when the current players need to be accessed, such as for dealing cards or determining +player turns.
+Retrieves the current total pot amount for the PokerPhase
.
N/A
+N/A
+Provides the total value of bets placed in the current phase, aiding in bet-related actions.
+N/A
+N/A
+Useful for calculating winnings or determining the total bet pool.
+Retrieves the position of the player assigned the small blind.
+N/A
+N/A
+Helps identify the player with the small blind, aiding in betting actions.
+N/A
+N/A
+Used to determine the small blind in betting rounds.
+Returns the number of listeners listening for the event named eventName
.
+If listener
is provided, it will return how many times the listener is found
+in the list of the listeners of the event.
The name of the event being listened for
+Optional
listener: FunctionThe event handler function
+Returns a copy of the array of listeners for the event named eventName
.
server.on('connection', (stream) => {
console.log('someone connected!');
});
console.log(util.inspect(server.listeners('connection')));
// Prints: [ [Function] ]
+
+
+Alias for emitter.removeListener()
.
Rest
...args: any[]Adds the listener
function to the end of the listeners array for the event
+named eventName
. No checks are made to see if the listener
has already
+been added. Multiple calls passing the same combination of eventName
and
+listener
will result in the listener
being added, and called, multiple times.
server.on('connection', (stream) => {
console.log('someone connected!');
});
+
+
+Returns a reference to the EventEmitter
, so that calls can be chained.
By default, event listeners are invoked in the order they are added. The emitter.prependListener()
method can be used as an alternative to add the
+event listener to the beginning of the listeners array.
import { EventEmitter } from 'node:events';
const myEE = new EventEmitter();
myEE.on('foo', () => console.log('a'));
myEE.prependListener('foo', () => console.log('b'));
myEE.emit('foo');
// Prints:
// b
// a
+
+
+The name of the event.
+The callback function
+Rest
...args: any[]Adds a one-time listener
function for the event named eventName
. The
+next time eventName
is triggered, this listener is removed and then invoked.
server.once('connection', (stream) => {
console.log('Ah, we have our first user!');
});
+
+
+Returns a reference to the EventEmitter
, so that calls can be chained.
By default, event listeners are invoked in the order they are added. The emitter.prependOnceListener()
method can be used as an alternative to add the
+event listener to the beginning of the listeners array.
import { EventEmitter } from 'node:events';
const myEE = new EventEmitter();
myEE.once('foo', () => console.log('a'));
myEE.prependOnceListener('foo', () => console.log('b'));
myEE.emit('foo');
// Prints:
// b
// a
+
+
+The name of the event.
+The callback function
+Rest
...args: any[]Adds the listener
function to the beginning of the listeners array for the
+event named eventName
. No checks are made to see if the listener
has
+already been added. Multiple calls passing the same combination of eventName
+and listener
will result in the listener
being added, and called, multiple times.
server.prependListener('connection', (stream) => {
console.log('someone connected!');
});
+
+
+Returns a reference to the EventEmitter
, so that calls can be chained.
The name of the event.
+The callback function
+Rest
...args: any[]Adds a one-timelistener
function for the event named eventName
to the beginning of the listeners array. The next time eventName
is triggered, this
+listener is removed, and then invoked.
server.prependOnceListener('connection', (stream) => {
console.log('Ah, we have our first user!');
});
+
+
+Returns a reference to the EventEmitter
, so that calls can be chained.
The name of the event.
+The callback function
+Rest
...args: any[]Returns a copy of the array of listeners for the event named eventName
,
+including any wrappers (such as those created by .once()
).
import { EventEmitter } from 'node:events';
const emitter = new EventEmitter();
emitter.once('log', () => console.log('log once'));
// Returns a new Array with a function `onceWrapper` which has a property
// `listener` which contains the original listener bound above
const listeners = emitter.rawListeners('log');
const logFnWrapper = listeners[0];
// Logs "log once" to the console and does not unbind the `once` event
logFnWrapper.listener();
// Logs "log once" to the console and removes the listener
logFnWrapper();
emitter.on('log', () => console.log('log persistently'));
// Will return a new Array with a single function bound by `.on()` above
const newListeners = emitter.rawListeners('log');
// Logs "log persistently" twice
newListeners[0]();
emitter.emit('log');
+
+
+Removes all listeners, or those of the specified eventName
.
It is bad practice to remove listeners added elsewhere in the code,
+particularly when the EventEmitter
instance was created by some other
+component or module (e.g. sockets or file streams).
Returns a reference to the EventEmitter
, so that calls can be chained.
Optional
eventName: string | symbolRemoves the specified listener
from the listener array for the event named eventName
.
const callback = (stream) => {
console.log('someone connected!');
};
server.on('connection', callback);
// ...
server.removeListener('connection', callback);
+
+
+removeListener()
will remove, at most, one instance of a listener from the
+listener array. If any single listener has been added multiple times to the
+listener array for the specified eventName
, then removeListener()
must be
+called multiple times to remove each instance.
Once an event is emitted, all listeners attached to it at the
+time of emitting are called in order. This implies that any removeListener()
or removeAllListeners()
calls after emitting and before the last listener finishes execution
+will not remove them fromemit()
in progress. Subsequent events behave as expected.
import { EventEmitter } from 'node:events';
class MyEmitter extends EventEmitter {}
const myEmitter = new MyEmitter();
const callbackA = () => {
console.log('A');
myEmitter.removeListener('event', callbackB);
};
const callbackB = () => {
console.log('B');
};
myEmitter.on('event', callbackA);
myEmitter.on('event', callbackB);
// callbackA removes listener callbackB but it will still be called.
// Internal listener array at time of emit [callbackA, callbackB]
myEmitter.emit('event');
// Prints:
// A
// B
// callbackB is now removed.
// Internal listener array [callbackA]
myEmitter.emit('event');
// Prints:
// A
+
+
+Because listeners are managed using an internal array, calling this will
+change the position indices of any listener registered after the listener
+being removed. This will not impact the order in which listeners are called,
+but it means that any copies of the listener array as returned by
+the emitter.listeners()
method will need to be recreated.
When a single function has been added as a handler multiple times for a single
+event (as in the example below), removeListener()
will remove the most
+recently added instance. In the example the once('ping')
listener is removed:
import { EventEmitter } from 'node:events';
const ee = new EventEmitter();
function pong() {
console.log('pong');
}
ee.on('ping', pong);
ee.once('ping', pong);
ee.removeListener('ping', pong);
ee.emit('ping');
ee.emit('ping');
+
+
+Returns a reference to the EventEmitter
, so that calls can be chained.
Rest
...args: any[]By default EventEmitter
s will print a warning if more than 10
listeners are
+added for a particular event. This is a useful default that helps finding
+memory leaks. The emitter.setMaxListeners()
method allows the limit to be
+modified for this specific EventEmitter
instance. The value can be set to Infinity
(or 0
) to indicate an unlimited number of listeners.
Returns a reference to the EventEmitter
, so that calls can be chained.
Static
addExperimental
Listens once to the abort
event on the provided signal
.
Listening to the abort
event on abort signals is unsafe and may
+lead to resource leaks since another third party with the signal can
+call e.stopImmediatePropagation()
. Unfortunately Node.js cannot change
+this since it would violate the web standard. Additionally, the original
+API makes it easy to forget to remove listeners.
This API allows safely using AbortSignal
s in Node.js APIs by solving these
+two issues by listening to the event such that stopImmediatePropagation
does
+not prevent the listener from running.
Returns a disposable so that it may be unsubscribed from more easily.
+import { addAbortListener } from 'node:events';
function example(signal) {
let disposable;
try {
signal.addEventListener('abort', (e) => e.stopImmediatePropagation());
disposable = addAbortListener(signal, (e) => {
// Do something when signal is aborted.
});
} finally {
disposable?.[Symbol.dispose]();
}
}
+
+
+Disposable that removes the abort
listener.
Static
getReturns a copy of the array of listeners for the event named eventName
.
For EventEmitter
s this behaves exactly the same as calling .listeners
on
+the emitter.
For EventTarget
s this is the only way to get the event listeners for the
+event target. This is useful for debugging and diagnostic purposes.
import { getEventListeners, EventEmitter } from 'node:events';
{
const ee = new EventEmitter();
const listener = () => console.log('Events are fun');
ee.on('foo', listener);
console.log(getEventListeners(ee, 'foo')); // [ [Function: listener] ]
}
{
const et = new EventTarget();
const listener = () => console.log('Events are fun');
et.addEventListener('foo', listener);
console.log(getEventListeners(et, 'foo')); // [ [Function: listener] ]
}
+
+
+Static
getReturns the currently set max amount of listeners.
+For EventEmitter
s this behaves exactly the same as calling .getMaxListeners
on
+the emitter.
For EventTarget
s this is the only way to get the max event listeners for the
+event target. If the number of event handlers on a single EventTarget exceeds
+the max set, the EventTarget will print a warning.
import { getMaxListeners, setMaxListeners, EventEmitter } from 'node:events';
{
const ee = new EventEmitter();
console.log(getMaxListeners(ee)); // 10
setMaxListeners(11, ee);
console.log(getMaxListeners(ee)); // 11
}
{
const et = new EventTarget();
console.log(getMaxListeners(et)); // 10
setMaxListeners(11, et);
console.log(getMaxListeners(et)); // 11
}
+
+
+Static
listenerA class method that returns the number of listeners for the given eventName
registered on the given emitter
.
import { EventEmitter, listenerCount } from 'node:events';
const myEmitter = new EventEmitter();
myEmitter.on('event', () => {});
myEmitter.on('event', () => {});
console.log(listenerCount(myEmitter, 'event'));
// Prints: 2
+
+
+The emitter to query
+The event name
+Static
onimport { on, EventEmitter } from 'node:events';
import process from 'node:process';
const ee = new EventEmitter();
// Emit later on
process.nextTick(() => {
ee.emit('foo', 'bar');
ee.emit('foo', 42);
});
for await (const event of on(ee, 'foo')) {
// The execution of this inner block is synchronous and it
// processes one event at a time (even with await). Do not use
// if concurrent execution is required.
console.log(event); // prints ['bar'] [42]
}
// Unreachable here
+
+
+Returns an AsyncIterator
that iterates eventName
events. It will throw
+if the EventEmitter
emits 'error'
. It removes all listeners when
+exiting the loop. The value
returned by each iteration is an array
+composed of the emitted event arguments.
An AbortSignal
can be used to cancel waiting on events:
import { on, EventEmitter } from 'node:events';
import process from 'node:process';
const ac = new AbortController();
(async () => {
const ee = new EventEmitter();
// Emit later on
process.nextTick(() => {
ee.emit('foo', 'bar');
ee.emit('foo', 42);
});
for await (const event of on(ee, 'foo', { signal: ac.signal })) {
// The execution of this inner block is synchronous and it
// processes one event at a time (even with await). Do not use
// if concurrent execution is required.
console.log(event); // prints ['bar'] [42]
}
// Unreachable here
})();
process.nextTick(() => ac.abort());
+
+
+Use the close
option to specify an array of event names that will end the iteration:
import { on, EventEmitter } from 'node:events';
import process from 'node:process';
const ee = new EventEmitter();
// Emit later on
process.nextTick(() => {
ee.emit('foo', 'bar');
ee.emit('foo', 42);
ee.emit('close');
});
for await (const event of on(ee, 'foo', { close: ['close'] })) {
console.log(event); // prints ['bar'] [42]
}
// the loop will exit after 'close' is emitted
console.log('done'); // prints 'done'
+
+
+Optional
options: StaticEventEmitterIteratorOptionsAn AsyncIterator
that iterates eventName
events emitted by the emitter
Optional
options: StaticEventEmitterIteratorOptionsStatic
onceCreates a Promise
that is fulfilled when the EventEmitter
emits the given
+event or that is rejected if the EventEmitter
emits 'error'
while waiting.
+The Promise
will resolve with an array of all the arguments emitted to the
+given event.
This method is intentionally generic and works with the web platform EventTarget interface, which has no special'error'
event
+semantics and does not listen to the 'error'
event.
import { once, EventEmitter } from 'node:events';
import process from 'node:process';
const ee = new EventEmitter();
process.nextTick(() => {
ee.emit('myevent', 42);
});
const [value] = await once(ee, 'myevent');
console.log(value);
const err = new Error('kaboom');
process.nextTick(() => {
ee.emit('error', err);
});
try {
await once(ee, 'myevent');
} catch (err) {
console.error('error happened', err);
}
+
+
+The special handling of the 'error'
event is only used when events.once()
is used to wait for another event. If events.once()
is used to wait for the
+'error'
event itself, then it is treated as any other kind of event without
+special handling:
import { EventEmitter, once } from 'node:events';
const ee = new EventEmitter();
once(ee, 'error')
.then(([err]) => console.log('ok', err.message))
.catch((err) => console.error('error', err.message));
ee.emit('error', new Error('boom'));
// Prints: ok boom
+
+
+An AbortSignal
can be used to cancel waiting for the event:
import { EventEmitter, once } from 'node:events';
const ee = new EventEmitter();
const ac = new AbortController();
async function foo(emitter, event, signal) {
try {
await once(emitter, event, { signal });
console.log('event emitted!');
} catch (error) {
if (error.name === 'AbortError') {
console.error('Waiting for the event was canceled!');
} else {
console.error('There was an error', error.message);
}
}
}
foo(ee, 'foo', ac.signal);
ac.abort(); // Abort waiting for the event
ee.emit('foo'); // Prints: Waiting for the event was canceled!
+
+
+Optional
options: StaticEventEmitterOptionsOptional
options: StaticEventEmitterOptionsStatic
setimport { setMaxListeners, EventEmitter } from 'node:events';
const target = new EventTarget();
const emitter = new EventEmitter();
setMaxListeners(5, target, emitter);
+
+
+Optional
n: numberA non-negative number. The maximum number of listeners per EventTarget
event.
Rest
...eventTargets: (EventEmitter<DefaultEventMap> | EventTarget)[]Zero or more {EventTarget} or {EventEmitter} instances. If none are specified, n
is set as the default max for all newly created {EventTarget} and {EventEmitter}
+objects.
PokerPlayerInterface
+Represents a player seated at the PokerTable.
+The player can place bets, fold, and manage their chip stack during the game.
constructor
+Creates an instance of a Deck with 52 cards. +Automatically initializes the deck with all combinations of ranks and suits.
+Optional
config: PokerPlayerConfigStatic
captureValue: boolean
+Change the default captureRejections
option on all new EventEmitter
objects.
Static
Readonly
captureValue: Symbol.for('nodejs.rejection')
See how to write a custom rejection handler
.
Static
defaultBy default, a maximum of 10
listeners can be registered for any single
+event. This limit can be changed for individual EventEmitter
instances
+using the emitter.setMaxListeners(n)
method. To change the default
+for allEventEmitter
instances, the events.defaultMaxListeners
property
+can be used. If this value is not a positive number, a RangeError
is thrown.
Take caution when setting the events.defaultMaxListeners
because the
+change affects all EventEmitter
instances, including those created before
+the change is made. However, calling emitter.setMaxListeners(n)
still has
+precedence over events.defaultMaxListeners
.
This is not a hard limit. The EventEmitter
instance will allow
+more listeners to be added but will output a trace warning to stderr indicating
+that a "possible EventEmitter memory leak" has been detected. For any single
+EventEmitter
, the emitter.getMaxListeners()
and emitter.setMaxListeners()
methods can be used to
+temporarily avoid this warning:
import { EventEmitter } from 'node:events';
const emitter = new EventEmitter();
emitter.setMaxListeners(emitter.getMaxListeners() + 1);
emitter.once('event', () => {
// do stuff
emitter.setMaxListeners(Math.max(emitter.getMaxListeners() - 1, 0));
});
+
+
+The --trace-warnings
command-line flag can be used to display the
+stack trace for such warnings.
The emitted warning can be inspected with process.on('warning')
and will
+have the additional emitter
, type
, and count
properties, referring to
+the event emitter instance, the event's name and the number of attached
+listeners, respectively.
+Its name
property is set to 'MaxListenersExceededWarning'
.
Static
Readonly
errorThis symbol shall be used to install a listener for only monitoring 'error'
events. Listeners installed using this symbol are called before the regular 'error'
listeners are called.
Installing a listener using this symbol does not change the behavior once an 'error'
event is emitted. Therefore, the process will still crash if no
+regular 'error'
listener is installed.
Protected
_setOptional
[captureRest
...args: AnyRestAlias for emitter.on(eventName, listener)
.
Rest
...args: any[]Synchronously calls each of the listeners registered for the event named eventName
, in the order they were registered, passing the supplied arguments
+to each.
Returns true
if the event had listeners, false
otherwise.
import { EventEmitter } from 'node:events';
const myEmitter = new EventEmitter();
// First listener
myEmitter.on('event', function firstListener() {
console.log('Helloooo! first listener');
});
// Second listener
myEmitter.on('event', function secondListener(arg1, arg2) {
console.log(`event with parameters ${arg1}, ${arg2} in second listener`);
});
// Third listener
myEmitter.on('event', function thirdListener(...args) {
const parameters = args.join(', ');
console.log(`event with parameters ${parameters} in third listener`);
});
console.log(myEmitter.listeners('event'));
myEmitter.emit('event', 1, 2, 3, 4, 5);
// Prints:
// [
// [Function: firstListener],
// [Function: secondListener],
// [Function: thirdListener]
// ]
// Helloooo! first listener
// event with parameters 1, 2 in second listener
// event with parameters 1, 2, 3, 4, 5 in third listener
+
+
+Rest
...args: AnyRestThe emitEvent
method is a public method for emitting events, with an optional configuration that allows
+middleware processing. Middleware functions can intercept and transform the event before it reaches the listeners,
+allowing custom validation or data modifications.
This method enables flexible event emission with support for middleware, providing a robust event processing
+mechanism in the BaseEventEmitter
. It’s useful for customizing event behavior based on application-specific needs.
N/A
+N/A
+This method can emit any event specified by eventName
, which can then be processed by middleware functions if defined.
eventName: string
- The name of the event to emit.options: { event: { data: { [key: string]: any }; [key: string]: any; }, middlewares?: Array<(event: BaseEventInterface, next: () => void) => void | false> }
+eventName
must be a valid string.options.event
should include relevant data for the event. If middlewares
are provided, they should be functions with an event and next parameter.void
- This method does not return a value.Use this method to emit events with middleware-based customization, which allows for specific processing +logic or transformations before the event reaches listeners.
+The name of the event to emit.
+Configuration for the event and optional middleware functions.
+Optional
middlewares?: ((event: BaseEventInterface<any>, next: (() => void)) => false | void)[]Returns an array listing the events for which the emitter has registered
+listeners. The values in the array are strings or Symbol
s.
import { EventEmitter } from 'node:events';
const myEE = new EventEmitter();
myEE.on('foo', () => {});
myEE.on('bar', () => {});
const sym = Symbol('symbol');
myEE.on(sym, () => {});
console.log(myEE.eventNames());
// Prints: [ 'foo', 'bar', Symbol(symbol) ]
+
+
+getHand
Returns the poker table's id
.
The poker table's id
.
Returns the current max listener value for the EventEmitter
which is either
+set by emitter.setMaxListeners(n)
or defaults to defaultMaxListeners.
Returns the number of listeners listening for the event named eventName
.
+If listener
is provided, it will return how many times the listener is found
+in the list of the listeners of the event.
The name of the event being listened for
+Optional
listener: FunctionThe event handler function
+Returns a copy of the array of listeners for the event named eventName
.
server.on('connection', (stream) => {
console.log('someone connected!');
});
console.log(util.inspect(server.listeners('connection')));
// Prints: [ [Function] ]
+
+
+Alias for emitter.removeListener()
.
Rest
...args: any[]Adds the listener
function to the end of the listeners array for the event
+named eventName
. No checks are made to see if the listener
has already
+been added. Multiple calls passing the same combination of eventName
and
+listener
will result in the listener
being added, and called, multiple times.
server.on('connection', (stream) => {
console.log('someone connected!');
});
+
+
+Returns a reference to the EventEmitter
, so that calls can be chained.
By default, event listeners are invoked in the order they are added. The emitter.prependListener()
method can be used as an alternative to add the
+event listener to the beginning of the listeners array.
import { EventEmitter } from 'node:events';
const myEE = new EventEmitter();
myEE.on('foo', () => console.log('a'));
myEE.prependListener('foo', () => console.log('b'));
myEE.emit('foo');
// Prints:
// b
// a
+
+
+The name of the event.
+The callback function
+Rest
...args: any[]Adds a one-time listener
function for the event named eventName
. The
+next time eventName
is triggered, this listener is removed and then invoked.
server.once('connection', (stream) => {
console.log('Ah, we have our first user!');
});
+
+
+Returns a reference to the EventEmitter
, so that calls can be chained.
By default, event listeners are invoked in the order they are added. The emitter.prependOnceListener()
method can be used as an alternative to add the
+event listener to the beginning of the listeners array.
import { EventEmitter } from 'node:events';
const myEE = new EventEmitter();
myEE.once('foo', () => console.log('a'));
myEE.prependOnceListener('foo', () => console.log('b'));
myEE.emit('foo');
// Prints:
// b
// a
+
+
+The name of the event.
+The callback function
+Rest
...args: any[]Adds the listener
function to the beginning of the listeners array for the
+event named eventName
. No checks are made to see if the listener
has
+already been added. Multiple calls passing the same combination of eventName
+and listener
will result in the listener
being added, and called, multiple times.
server.prependListener('connection', (stream) => {
console.log('someone connected!');
});
+
+
+Returns a reference to the EventEmitter
, so that calls can be chained.
The name of the event.
+The callback function
+Rest
...args: any[]Adds a one-timelistener
function for the event named eventName
to the beginning of the listeners array. The next time eventName
is triggered, this
+listener is removed, and then invoked.
server.prependOnceListener('connection', (stream) => {
console.log('Ah, we have our first user!');
});
+
+
+Returns a reference to the EventEmitter
, so that calls can be chained.
The name of the event.
+The callback function
+Rest
...args: any[]Returns a copy of the array of listeners for the event named eventName
,
+including any wrappers (such as those created by .once()
).
import { EventEmitter } from 'node:events';
const emitter = new EventEmitter();
emitter.once('log', () => console.log('log once'));
// Returns a new Array with a function `onceWrapper` which has a property
// `listener` which contains the original listener bound above
const listeners = emitter.rawListeners('log');
const logFnWrapper = listeners[0];
// Logs "log once" to the console and does not unbind the `once` event
logFnWrapper.listener();
// Logs "log once" to the console and removes the listener
logFnWrapper();
emitter.on('log', () => console.log('log persistently'));
// Will return a new Array with a single function bound by `.on()` above
const newListeners = emitter.rawListeners('log');
// Logs "log persistently" twice
newListeners[0]();
emitter.emit('log');
+
+
+Removes all listeners, or those of the specified eventName
.
It is bad practice to remove listeners added elsewhere in the code,
+particularly when the EventEmitter
instance was created by some other
+component or module (e.g. sockets or file streams).
Returns a reference to the EventEmitter
, so that calls can be chained.
Optional
eventName: string | symbolRemoves the specified listener
from the listener array for the event named eventName
.
const callback = (stream) => {
console.log('someone connected!');
};
server.on('connection', callback);
// ...
server.removeListener('connection', callback);
+
+
+removeListener()
will remove, at most, one instance of a listener from the
+listener array. If any single listener has been added multiple times to the
+listener array for the specified eventName
, then removeListener()
must be
+called multiple times to remove each instance.
Once an event is emitted, all listeners attached to it at the
+time of emitting are called in order. This implies that any removeListener()
or removeAllListeners()
calls after emitting and before the last listener finishes execution
+will not remove them fromemit()
in progress. Subsequent events behave as expected.
import { EventEmitter } from 'node:events';
class MyEmitter extends EventEmitter {}
const myEmitter = new MyEmitter();
const callbackA = () => {
console.log('A');
myEmitter.removeListener('event', callbackB);
};
const callbackB = () => {
console.log('B');
};
myEmitter.on('event', callbackA);
myEmitter.on('event', callbackB);
// callbackA removes listener callbackB but it will still be called.
// Internal listener array at time of emit [callbackA, callbackB]
myEmitter.emit('event');
// Prints:
// A
// B
// callbackB is now removed.
// Internal listener array [callbackA]
myEmitter.emit('event');
// Prints:
// A
+
+
+Because listeners are managed using an internal array, calling this will
+change the position indices of any listener registered after the listener
+being removed. This will not impact the order in which listeners are called,
+but it means that any copies of the listener array as returned by
+the emitter.listeners()
method will need to be recreated.
When a single function has been added as a handler multiple times for a single
+event (as in the example below), removeListener()
will remove the most
+recently added instance. In the example the once('ping')
listener is removed:
import { EventEmitter } from 'node:events';
const ee = new EventEmitter();
function pong() {
console.log('pong');
}
ee.on('ping', pong);
ee.once('ping', pong);
ee.removeListener('ping', pong);
ee.emit('ping');
ee.emit('ping');
+
+
+Returns a reference to the EventEmitter
, so that calls can be chained.
Rest
...args: any[]By default EventEmitter
s will print a warning if more than 10
listeners are
+added for a particular event. This is a useful default that helps finding
+memory leaks. The emitter.setMaxListeners()
method allows the limit to be
+modified for this specific EventEmitter
instance. The value can be set to Infinity
(or 0
) to indicate an unlimited number of listeners.
Returns a reference to the EventEmitter
, so that calls can be chained.
Sets the name of the PokerRoom
, allowing the name to be updated or customized.
N/A
- This method is part of the PokerRoomInterface
and does not implement any external methods.
N/A
- This method does not override any superclass or parent methods.
The setName
method is used to assign a specific name to a PokerRoom
, which helps distinguish it within the system.
+This is essential for systems where rooms need to be identifiable and manageable through a unique name.
N/A
- No events are emitted by this method.
name
: A string representing the new name for the room. It must be a valid, non-empty string to ensure
+the room has a clear, identifiable label.name
parameter should be a non-empty string to provide meaningful identification.name
that was set for the PokerRoom
.Use this method to set or update the name of a room in a system where unique or identifiable room names +are necessary for reference.
+The new name for the PokerRoom
.
Static
addExperimental
Listens once to the abort
event on the provided signal
.
Listening to the abort
event on abort signals is unsafe and may
+lead to resource leaks since another third party with the signal can
+call e.stopImmediatePropagation()
. Unfortunately Node.js cannot change
+this since it would violate the web standard. Additionally, the original
+API makes it easy to forget to remove listeners.
This API allows safely using AbortSignal
s in Node.js APIs by solving these
+two issues by listening to the event such that stopImmediatePropagation
does
+not prevent the listener from running.
Returns a disposable so that it may be unsubscribed from more easily.
+import { addAbortListener } from 'node:events';
function example(signal) {
let disposable;
try {
signal.addEventListener('abort', (e) => e.stopImmediatePropagation());
disposable = addAbortListener(signal, (e) => {
// Do something when signal is aborted.
});
} finally {
disposable?.[Symbol.dispose]();
}
}
+
+
+Disposable that removes the abort
listener.
Static
getReturns a copy of the array of listeners for the event named eventName
.
For EventEmitter
s this behaves exactly the same as calling .listeners
on
+the emitter.
For EventTarget
s this is the only way to get the event listeners for the
+event target. This is useful for debugging and diagnostic purposes.
import { getEventListeners, EventEmitter } from 'node:events';
{
const ee = new EventEmitter();
const listener = () => console.log('Events are fun');
ee.on('foo', listener);
console.log(getEventListeners(ee, 'foo')); // [ [Function: listener] ]
}
{
const et = new EventTarget();
const listener = () => console.log('Events are fun');
et.addEventListener('foo', listener);
console.log(getEventListeners(et, 'foo')); // [ [Function: listener] ]
}
+
+
+Static
getReturns the currently set max amount of listeners.
+For EventEmitter
s this behaves exactly the same as calling .getMaxListeners
on
+the emitter.
For EventTarget
s this is the only way to get the max event listeners for the
+event target. If the number of event handlers on a single EventTarget exceeds
+the max set, the EventTarget will print a warning.
import { getMaxListeners, setMaxListeners, EventEmitter } from 'node:events';
{
const ee = new EventEmitter();
console.log(getMaxListeners(ee)); // 10
setMaxListeners(11, ee);
console.log(getMaxListeners(ee)); // 11
}
{
const et = new EventTarget();
console.log(getMaxListeners(et)); // 10
setMaxListeners(11, et);
console.log(getMaxListeners(et)); // 11
}
+
+
+Static
listenerA class method that returns the number of listeners for the given eventName
registered on the given emitter
.
import { EventEmitter, listenerCount } from 'node:events';
const myEmitter = new EventEmitter();
myEmitter.on('event', () => {});
myEmitter.on('event', () => {});
console.log(listenerCount(myEmitter, 'event'));
// Prints: 2
+
+
+The emitter to query
+The event name
+Static
onimport { on, EventEmitter } from 'node:events';
import process from 'node:process';
const ee = new EventEmitter();
// Emit later on
process.nextTick(() => {
ee.emit('foo', 'bar');
ee.emit('foo', 42);
});
for await (const event of on(ee, 'foo')) {
// The execution of this inner block is synchronous and it
// processes one event at a time (even with await). Do not use
// if concurrent execution is required.
console.log(event); // prints ['bar'] [42]
}
// Unreachable here
+
+
+Returns an AsyncIterator
that iterates eventName
events. It will throw
+if the EventEmitter
emits 'error'
. It removes all listeners when
+exiting the loop. The value
returned by each iteration is an array
+composed of the emitted event arguments.
An AbortSignal
can be used to cancel waiting on events:
import { on, EventEmitter } from 'node:events';
import process from 'node:process';
const ac = new AbortController();
(async () => {
const ee = new EventEmitter();
// Emit later on
process.nextTick(() => {
ee.emit('foo', 'bar');
ee.emit('foo', 42);
});
for await (const event of on(ee, 'foo', { signal: ac.signal })) {
// The execution of this inner block is synchronous and it
// processes one event at a time (even with await). Do not use
// if concurrent execution is required.
console.log(event); // prints ['bar'] [42]
}
// Unreachable here
})();
process.nextTick(() => ac.abort());
+
+
+Use the close
option to specify an array of event names that will end the iteration:
import { on, EventEmitter } from 'node:events';
import process from 'node:process';
const ee = new EventEmitter();
// Emit later on
process.nextTick(() => {
ee.emit('foo', 'bar');
ee.emit('foo', 42);
ee.emit('close');
});
for await (const event of on(ee, 'foo', { close: ['close'] })) {
console.log(event); // prints ['bar'] [42]
}
// the loop will exit after 'close' is emitted
console.log('done'); // prints 'done'
+
+
+Optional
options: StaticEventEmitterIteratorOptionsAn AsyncIterator
that iterates eventName
events emitted by the emitter
Optional
options: StaticEventEmitterIteratorOptionsStatic
onceCreates a Promise
that is fulfilled when the EventEmitter
emits the given
+event or that is rejected if the EventEmitter
emits 'error'
while waiting.
+The Promise
will resolve with an array of all the arguments emitted to the
+given event.
This method is intentionally generic and works with the web platform EventTarget interface, which has no special'error'
event
+semantics and does not listen to the 'error'
event.
import { once, EventEmitter } from 'node:events';
import process from 'node:process';
const ee = new EventEmitter();
process.nextTick(() => {
ee.emit('myevent', 42);
});
const [value] = await once(ee, 'myevent');
console.log(value);
const err = new Error('kaboom');
process.nextTick(() => {
ee.emit('error', err);
});
try {
await once(ee, 'myevent');
} catch (err) {
console.error('error happened', err);
}
+
+
+The special handling of the 'error'
event is only used when events.once()
is used to wait for another event. If events.once()
is used to wait for the
+'error'
event itself, then it is treated as any other kind of event without
+special handling:
import { EventEmitter, once } from 'node:events';
const ee = new EventEmitter();
once(ee, 'error')
.then(([err]) => console.log('ok', err.message))
.catch((err) => console.error('error', err.message));
ee.emit('error', new Error('boom'));
// Prints: ok boom
+
+
+An AbortSignal
can be used to cancel waiting for the event:
import { EventEmitter, once } from 'node:events';
const ee = new EventEmitter();
const ac = new AbortController();
async function foo(emitter, event, signal) {
try {
await once(emitter, event, { signal });
console.log('event emitted!');
} catch (error) {
if (error.name === 'AbortError') {
console.error('Waiting for the event was canceled!');
} else {
console.error('There was an error', error.message);
}
}
}
foo(ee, 'foo', ac.signal);
ac.abort(); // Abort waiting for the event
ee.emit('foo'); // Prints: Waiting for the event was canceled!
+
+
+Optional
options: StaticEventEmitterOptionsOptional
options: StaticEventEmitterOptionsStatic
setimport { setMaxListeners, EventEmitter } from 'node:events';
const target = new EventTarget();
const emitter = new EventEmitter();
setMaxListeners(5, target, emitter);
+
+
+Optional
n: numberA non-negative number. The maximum number of listeners per EventTarget
event.
Rest
...eventTargets: (EventEmitter<DefaultEventMap> | EventTarget)[]Zero or more {EventTarget} or {EventEmitter} instances. If none are specified, n
is set as the default max for all newly created {EventTarget} and {EventEmitter}
+objects.
PokerRoom
+Represents a PokerRoom within a Casino that holds a single PokerTable. The PokerRoom manages the player queue, automatically assigning players to the PokerTable as seats become available.
+This class extends BaseEventEmitter
and implements the PokerRoomInterface
interface.
The constructor
initializes the Casino
class.
Optional
config: PokerRoomConfigStatic
captureValue: boolean
+Change the default captureRejections
option on all new EventEmitter
objects.
Static
Readonly
captureValue: Symbol.for('nodejs.rejection')
See how to write a custom rejection handler
.
Static
defaultBy default, a maximum of 10
listeners can be registered for any single
+event. This limit can be changed for individual EventEmitter
instances
+using the emitter.setMaxListeners(n)
method. To change the default
+for allEventEmitter
instances, the events.defaultMaxListeners
property
+can be used. If this value is not a positive number, a RangeError
is thrown.
Take caution when setting the events.defaultMaxListeners
because the
+change affects all EventEmitter
instances, including those created before
+the change is made. However, calling emitter.setMaxListeners(n)
still has
+precedence over events.defaultMaxListeners
.
This is not a hard limit. The EventEmitter
instance will allow
+more listeners to be added but will output a trace warning to stderr indicating
+that a "possible EventEmitter memory leak" has been detected. For any single
+EventEmitter
, the emitter.getMaxListeners()
and emitter.setMaxListeners()
methods can be used to
+temporarily avoid this warning:
import { EventEmitter } from 'node:events';
const emitter = new EventEmitter();
emitter.setMaxListeners(emitter.getMaxListeners() + 1);
emitter.once('event', () => {
// do stuff
emitter.setMaxListeners(Math.max(emitter.getMaxListeners() - 1, 0));
});
+
+
+The --trace-warnings
command-line flag can be used to display the
+stack trace for such warnings.
The emitted warning can be inspected with process.on('warning')
and will
+have the additional emitter
, type
, and count
properties, referring to
+the event emitter instance, the event's name and the number of attached
+listeners, respectively.
+Its name
property is set to 'MaxListenersExceededWarning'
.
Static
Readonly
errorThis symbol shall be used to install a listener for only monitoring 'error'
events. Listeners installed using this symbol are called before the regular 'error'
listeners are called.
Installing a listener using this symbol does not change the behavior once an 'error'
event is emitted. Therefore, the process will still crash if no
+regular 'error'
listener is installed.
Protected
_createCreates a new PokerRoom
instance based on the provided configuration and adds it to the Casino's rooms list.
N/A
N/A
Allows the Casino to dynamically create new rooms as needed by providing specific room configurations.
+CasinoEventName.ROOM_CREATED
event, enabling listeners to respond to the creation of a new room.config
: A PokerRoomConfig
object containing details like name
, tableSize
, smallBlind
, and bigBlind
.N/A
PokerRoomInterface
instance.Primarily used within subclasses or protected methods to dynamically create and add rooms to the Casino.
+Optional
config: PokerTableConfigConfiguration settings for creating a new PokerRoom
.
class SpecialCasino extends Casino {
public createSpecialRoom(config: PokerRoomConfig): PokerRoomInterface {
return this._createRoom(config);
}
}
const specialCasino = new SpecialCasino();
const newRoom = specialCasino.createSpecialRoom({ name: "Champions Lounge", tableSize: 10, smallBlind: 100, bigBlind: 200 });
console.log(newRoom.getName()); // Outputs: "Champions Lounge"
+
+
+Protected
_setProtected
_setOptional
[captureRest
...args: AnyRestAlias for emitter.on(eventName, listener)
.
Rest
...args: any[]Creates a new PokerRoom
instance based on the provided configuration and adds it to the Casino's rooms list.
N/A
N/A
Allows the Casino to dynamically create new rooms as needed by providing specific room configurations.
+CasinoEventName.ROOM_CREATED
event, enabling listeners to respond to the creation of a new room.config
: A PokerRoomConfig
object containing details like name
, tableSize
, smallBlind
, and bigBlind
.N/A
PokerRoomInterface
instance.Primarily used within subclasses or protected methods to dynamically create and add rooms to the Casino.
+Configuration settings for creating a new PokerRoom
.
class SpecialCasino extends Casino {
public createSpecialRoom(config: PokerRoomConfig): PokerRoomInterface {
return this._createRoom(config);
}
}
const specialCasino = new SpecialCasino();
const newRoom = specialCasino.createSpecialRoom({ name: "Champions Lounge", tableSize: 10, smallBlind: 100, bigBlind: 200 });
console.log(newRoom.getName()); // Outputs: "Champions Lounge"
+
+
+Synchronously calls each of the listeners registered for the event named eventName
, in the order they were registered, passing the supplied arguments
+to each.
Returns true
if the event had listeners, false
otherwise.
import { EventEmitter } from 'node:events';
const myEmitter = new EventEmitter();
// First listener
myEmitter.on('event', function firstListener() {
console.log('Helloooo! first listener');
});
// Second listener
myEmitter.on('event', function secondListener(arg1, arg2) {
console.log(`event with parameters ${arg1}, ${arg2} in second listener`);
});
// Third listener
myEmitter.on('event', function thirdListener(...args) {
const parameters = args.join(', ');
console.log(`event with parameters ${parameters} in third listener`);
});
console.log(myEmitter.listeners('event'));
myEmitter.emit('event', 1, 2, 3, 4, 5);
// Prints:
// [
// [Function: firstListener],
// [Function: secondListener],
// [Function: thirdListener]
// ]
// Helloooo! first listener
// event with parameters 1, 2 in second listener
// event with parameters 1, 2, 3, 4, 5 in third listener
+
+
+Rest
...args: AnyRestThe emitEvent
method is a public method for emitting events, with an optional configuration that allows
+middleware processing. Middleware functions can intercept and transform the event before it reaches the listeners,
+allowing custom validation or data modifications.
This method enables flexible event emission with support for middleware, providing a robust event processing
+mechanism in the BaseEventEmitter
. It’s useful for customizing event behavior based on application-specific needs.
N/A
+N/A
+This method can emit any event specified by eventName
, which can then be processed by middleware functions if defined.
eventName: string
- The name of the event to emit.options: { event: { data: { [key: string]: any }; [key: string]: any; }, middlewares?: Array<(event: BaseEventInterface, next: () => void) => void | false> }
+eventName
must be a valid string.options.event
should include relevant data for the event. If middlewares
are provided, they should be functions with an event and next parameter.void
- This method does not return a value.Use this method to emit events with middleware-based customization, which allows for specific processing +logic or transformations before the event reaches listeners.
+The name of the event to emit.
+Configuration for the event and optional middleware functions.
+Optional
middlewares?: ((event: BaseEventInterface<any>, next: (() => void)) => false | void)[]Returns an array listing the events for which the emitter has registered
+listeners. The values in the array are strings or Symbol
s.
import { EventEmitter } from 'node:events';
const myEE = new EventEmitter();
myEE.on('foo', () => {});
myEE.on('bar', () => {});
const sym = Symbol('symbol');
myEE.on(sym, () => {});
console.log(myEE.eventNames());
// Prints: [ 'foo', 'bar', Symbol(symbol) ]
+
+
+Creates a new PokerRoom
instance based on the provided configuration and adds it to the Casino's rooms list.
N/A
N/A
Allows the Casino to dynamically create new rooms as needed by providing specific room configurations.
+CasinoEventName.ROOM_CREATED
event, enabling listeners to respond to the creation of a new room.config
: A PokerRoomConfig
object containing details like name
, tableSize
, smallBlind
, and bigBlind
.N/A
PokerRoomInterface
instance.Primarily used within subclasses or protected methods to dynamically create and add rooms to the Casino.
+class SpecialCasino extends Casino {
public createSpecialRoom(config: PokerRoomConfig): PokerRoomInterface {
return this._createRoom(config);
}
}
const specialCasino = new SpecialCasino();
const newRoom = specialCasino.createSpecialRoom({ name: "Champions Lounge", tableSize: 10, smallBlind: 100, bigBlind: 200 });
console.log(newRoom.getName()); // Outputs: "Champions Lounge"
+
+
+Returns the current max listener value for the EventEmitter
which is either
+set by emitter.setMaxListeners(n)
or defaults to defaultMaxListeners.
Retrieves the current name of the PokerRoom
.
N/A
- This method is defined within PokerRoomInterface
and is implemented by any class adhering to this interface.
N/A
- This method does not override any superclass or parent methods.
The getName
method enables access to the current name of a PokerRoom
, which can be essential for
+identification, logging, and displaying room information to users.
N/A
- No events are emitted by this method.
N/A
- This method does not require any parameters.
N/A
- This method simply returns the current name as set by setName
.
PokerRoom
as a string.Use this method to fetch the current name of a PokerRoom
. This can be particularly helpful for displaying
+or verifying the room name during operations.
PokerRoom
.Retrieves the associated PokerTable
instance within the PokerRoom
.
N/A
- This method does not implement external interfaces.
N/A
- This method does not override any superclass or parent methods.
The getTable
method provides access to the PokerTable
instance that is actively managed by the PokerRoom
.
+This can be used to view table configuration, status, and player seating arrangements.
N/A
- This method does not emit any events.
N/A
- No parameters are required for this method.
N/A
- This method does not modify the table, only retrieves it.
PokerTableInterface
instance currently set for the room.Use this method to access the poker table associated with a specific room. This allows for table-specific +operations and inquiries.
+PokerTable
instance associated with this room.Checks if a provided index is within the valid range of the Casino’s room list.
+Implements the isValidIndex
method of CasinoInterface
.
N/A
This method helps validate that an index is within the valid bounds of the Casino’s room list. It prevents +out-of-bound errors and ensures that methods calling on rooms by index are provided with a valid reference.
+N/A
index
: A zero-based integer representing the position of a room in the Casino's managed list of rooms.index
should be a non-negative integer and within the bounds of the __rooms
array.true
if the index is within bounds.Error
if the index is out of range.Call this method before performing operations that require a valid room index to prevent out-of-bounds errors. +Can be used in any index-based access patterns for room retrieval or modification.
+The zero-based index to validate.
+true
if the index is within bounds.Returns the number of listeners listening for the event named eventName
.
+If listener
is provided, it will return how many times the listener is found
+in the list of the listeners of the event.
The name of the event being listened for
+Optional
listener: FunctionThe event handler function
+Returns a copy of the array of listeners for the event named eventName
.
server.on('connection', (stream) => {
console.log('someone connected!');
});
console.log(util.inspect(server.listeners('connection')));
// Prints: [ [Function] ]
+
+
+Alias for emitter.removeListener()
.
Rest
...args: any[]Adds the listener
function to the end of the listeners array for the event
+named eventName
. No checks are made to see if the listener
has already
+been added. Multiple calls passing the same combination of eventName
and
+listener
will result in the listener
being added, and called, multiple times.
server.on('connection', (stream) => {
console.log('someone connected!');
});
+
+
+Returns a reference to the EventEmitter
, so that calls can be chained.
By default, event listeners are invoked in the order they are added. The emitter.prependListener()
method can be used as an alternative to add the
+event listener to the beginning of the listeners array.
import { EventEmitter } from 'node:events';
const myEE = new EventEmitter();
myEE.on('foo', () => console.log('a'));
myEE.prependListener('foo', () => console.log('b'));
myEE.emit('foo');
// Prints:
// b
// a
+
+
+The name of the event.
+The callback function
+Rest
...args: any[]Adds a one-time listener
function for the event named eventName
. The
+next time eventName
is triggered, this listener is removed and then invoked.
server.once('connection', (stream) => {
console.log('Ah, we have our first user!');
});
+
+
+Returns a reference to the EventEmitter
, so that calls can be chained.
By default, event listeners are invoked in the order they are added. The emitter.prependOnceListener()
method can be used as an alternative to add the
+event listener to the beginning of the listeners array.
import { EventEmitter } from 'node:events';
const myEE = new EventEmitter();
myEE.once('foo', () => console.log('a'));
myEE.prependOnceListener('foo', () => console.log('b'));
myEE.emit('foo');
// Prints:
// b
// a
+
+
+The name of the event.
+The callback function
+Rest
...args: any[]Adds the listener
function to the beginning of the listeners array for the
+event named eventName
. No checks are made to see if the listener
has
+already been added. Multiple calls passing the same combination of eventName
+and listener
will result in the listener
being added, and called, multiple times.
server.prependListener('connection', (stream) => {
console.log('someone connected!');
});
+
+
+Returns a reference to the EventEmitter
, so that calls can be chained.
The name of the event.
+The callback function
+Rest
...args: any[]Adds a one-timelistener
function for the event named eventName
to the beginning of the listeners array. The next time eventName
is triggered, this
+listener is removed, and then invoked.
server.prependOnceListener('connection', (stream) => {
console.log('Ah, we have our first user!');
});
+
+
+Returns a reference to the EventEmitter
, so that calls can be chained.
The name of the event.
+The callback function
+Rest
...args: any[]Returns a copy of the array of listeners for the event named eventName
,
+including any wrappers (such as those created by .once()
).
import { EventEmitter } from 'node:events';
const emitter = new EventEmitter();
emitter.once('log', () => console.log('log once'));
// Returns a new Array with a function `onceWrapper` which has a property
// `listener` which contains the original listener bound above
const listeners = emitter.rawListeners('log');
const logFnWrapper = listeners[0];
// Logs "log once" to the console and does not unbind the `once` event
logFnWrapper.listener();
// Logs "log once" to the console and removes the listener
logFnWrapper();
emitter.on('log', () => console.log('log persistently'));
// Will return a new Array with a single function bound by `.on()` above
const newListeners = emitter.rawListeners('log');
// Logs "log persistently" twice
newListeners[0]();
emitter.emit('log');
+
+
+Removes all listeners, or those of the specified eventName
.
It is bad practice to remove listeners added elsewhere in the code,
+particularly when the EventEmitter
instance was created by some other
+component or module (e.g. sockets or file streams).
Returns a reference to the EventEmitter
, so that calls can be chained.
Optional
eventName: string | symbolRemoves the specified listener
from the listener array for the event named eventName
.
const callback = (stream) => {
console.log('someone connected!');
};
server.on('connection', callback);
// ...
server.removeListener('connection', callback);
+
+
+removeListener()
will remove, at most, one instance of a listener from the
+listener array. If any single listener has been added multiple times to the
+listener array for the specified eventName
, then removeListener()
must be
+called multiple times to remove each instance.
Once an event is emitted, all listeners attached to it at the
+time of emitting are called in order. This implies that any removeListener()
or removeAllListeners()
calls after emitting and before the last listener finishes execution
+will not remove them fromemit()
in progress. Subsequent events behave as expected.
import { EventEmitter } from 'node:events';
class MyEmitter extends EventEmitter {}
const myEmitter = new MyEmitter();
const callbackA = () => {
console.log('A');
myEmitter.removeListener('event', callbackB);
};
const callbackB = () => {
console.log('B');
};
myEmitter.on('event', callbackA);
myEmitter.on('event', callbackB);
// callbackA removes listener callbackB but it will still be called.
// Internal listener array at time of emit [callbackA, callbackB]
myEmitter.emit('event');
// Prints:
// A
// B
// callbackB is now removed.
// Internal listener array [callbackA]
myEmitter.emit('event');
// Prints:
// A
+
+
+Because listeners are managed using an internal array, calling this will
+change the position indices of any listener registered after the listener
+being removed. This will not impact the order in which listeners are called,
+but it means that any copies of the listener array as returned by
+the emitter.listeners()
method will need to be recreated.
When a single function has been added as a handler multiple times for a single
+event (as in the example below), removeListener()
will remove the most
+recently added instance. In the example the once('ping')
listener is removed:
import { EventEmitter } from 'node:events';
const ee = new EventEmitter();
function pong() {
console.log('pong');
}
ee.on('ping', pong);
ee.once('ping', pong);
ee.removeListener('ping', pong);
ee.emit('ping');
ee.emit('ping');
+
+
+Returns a reference to the EventEmitter
, so that calls can be chained.
Rest
...args: any[]By default EventEmitter
s will print a warning if more than 10
listeners are
+added for a particular event. This is a useful default that helps finding
+memory leaks. The emitter.setMaxListeners()
method allows the limit to be
+modified for this specific EventEmitter
instance. The value can be set to Infinity
(or 0
) to indicate an unlimited number of listeners.
Returns a reference to the EventEmitter
, so that calls can be chained.
Sets the name of the PokerRoom
, allowing the name to be updated or customized.
N/A
- This method is part of the PokerRoomInterface
and does not implement any external methods.
N/A
- This method does not override any superclass or parent methods.
The setName
method is used to assign a specific name to a PokerRoom
, which helps distinguish it within the system.
+This is essential for systems where rooms need to be identifiable and manageable through a unique name.
N/A
- No events are emitted by this method.
name
: A string representing the new name for the room. It must be a valid, non-empty string to ensure
+the room has a clear, identifiable label.name
parameter should be a non-empty string to provide meaningful identification.name
that was set for the PokerRoom
.Use this method to set or update the name of a room in a system where unique or identifiable room names +are necessary for reference.
+The new name for the PokerRoom
.
Sets the table configuration within the PokerRoom
. The table configuration determines essential
+settings for the poker table, such as table size, small blind, and big blind values.
N/A
- This method is part of the PokerRoomInterface
and does not implement any external methods.
N/A
- This method does not override any superclass or parent methods.
The setTables
method allows configuration or reconfiguration of the poker table within a room.
+Properly setting up the table configuration is vital for game mechanics and player experience.
N/A
- No events are emitted by this method.
table
: A PokerTableInterface
instance containing configuration details for the room’s table.table
parameter should be a valid instance of PokerTableInterface
, configured with necessary game parameters.PokerTableInterface
instance after updating it within the room.Call this method to configure or update the settings of a poker table in the room. This helps ensure +all game-related settings, such as seating and blinds, are properly managed.
+The configuration settings for the poker table.
+Returns the total number of PokerRoom
instances currently managed by the Casino.
Implements the roomCount
method of CasinoInterface
.
N/A
Provides a simple way to check how many poker rooms the Casino is currently managing. Useful for general +information about the Casino's state and for validating indices or conditions that depend on room count.
+N/A
N/A
N/A
This method is useful for any scenario where the total number of active rooms is needed, such as iterating +over all rooms or validating index-based operations.
+Static
addExperimental
Listens once to the abort
event on the provided signal
.
Listening to the abort
event on abort signals is unsafe and may
+lead to resource leaks since another third party with the signal can
+call e.stopImmediatePropagation()
. Unfortunately Node.js cannot change
+this since it would violate the web standard. Additionally, the original
+API makes it easy to forget to remove listeners.
This API allows safely using AbortSignal
s in Node.js APIs by solving these
+two issues by listening to the event such that stopImmediatePropagation
does
+not prevent the listener from running.
Returns a disposable so that it may be unsubscribed from more easily.
+import { addAbortListener } from 'node:events';
function example(signal) {
let disposable;
try {
signal.addEventListener('abort', (e) => e.stopImmediatePropagation());
disposable = addAbortListener(signal, (e) => {
// Do something when signal is aborted.
});
} finally {
disposable?.[Symbol.dispose]();
}
}
+
+
+Disposable that removes the abort
listener.
Static
getReturns a copy of the array of listeners for the event named eventName
.
For EventEmitter
s this behaves exactly the same as calling .listeners
on
+the emitter.
For EventTarget
s this is the only way to get the event listeners for the
+event target. This is useful for debugging and diagnostic purposes.
import { getEventListeners, EventEmitter } from 'node:events';
{
const ee = new EventEmitter();
const listener = () => console.log('Events are fun');
ee.on('foo', listener);
console.log(getEventListeners(ee, 'foo')); // [ [Function: listener] ]
}
{
const et = new EventTarget();
const listener = () => console.log('Events are fun');
et.addEventListener('foo', listener);
console.log(getEventListeners(et, 'foo')); // [ [Function: listener] ]
}
+
+
+Static
getReturns the currently set max amount of listeners.
+For EventEmitter
s this behaves exactly the same as calling .getMaxListeners
on
+the emitter.
For EventTarget
s this is the only way to get the max event listeners for the
+event target. If the number of event handlers on a single EventTarget exceeds
+the max set, the EventTarget will print a warning.
import { getMaxListeners, setMaxListeners, EventEmitter } from 'node:events';
{
const ee = new EventEmitter();
console.log(getMaxListeners(ee)); // 10
setMaxListeners(11, ee);
console.log(getMaxListeners(ee)); // 11
}
{
const et = new EventTarget();
console.log(getMaxListeners(et)); // 10
setMaxListeners(11, et);
console.log(getMaxListeners(et)); // 11
}
+
+
+Static
listenerA class method that returns the number of listeners for the given eventName
registered on the given emitter
.
import { EventEmitter, listenerCount } from 'node:events';
const myEmitter = new EventEmitter();
myEmitter.on('event', () => {});
myEmitter.on('event', () => {});
console.log(listenerCount(myEmitter, 'event'));
// Prints: 2
+
+
+The emitter to query
+The event name
+Static
onimport { on, EventEmitter } from 'node:events';
import process from 'node:process';
const ee = new EventEmitter();
// Emit later on
process.nextTick(() => {
ee.emit('foo', 'bar');
ee.emit('foo', 42);
});
for await (const event of on(ee, 'foo')) {
// The execution of this inner block is synchronous and it
// processes one event at a time (even with await). Do not use
// if concurrent execution is required.
console.log(event); // prints ['bar'] [42]
}
// Unreachable here
+
+
+Returns an AsyncIterator
that iterates eventName
events. It will throw
+if the EventEmitter
emits 'error'
. It removes all listeners when
+exiting the loop. The value
returned by each iteration is an array
+composed of the emitted event arguments.
An AbortSignal
can be used to cancel waiting on events:
import { on, EventEmitter } from 'node:events';
import process from 'node:process';
const ac = new AbortController();
(async () => {
const ee = new EventEmitter();
// Emit later on
process.nextTick(() => {
ee.emit('foo', 'bar');
ee.emit('foo', 42);
});
for await (const event of on(ee, 'foo', { signal: ac.signal })) {
// The execution of this inner block is synchronous and it
// processes one event at a time (even with await). Do not use
// if concurrent execution is required.
console.log(event); // prints ['bar'] [42]
}
// Unreachable here
})();
process.nextTick(() => ac.abort());
+
+
+Use the close
option to specify an array of event names that will end the iteration:
import { on, EventEmitter } from 'node:events';
import process from 'node:process';
const ee = new EventEmitter();
// Emit later on
process.nextTick(() => {
ee.emit('foo', 'bar');
ee.emit('foo', 42);
ee.emit('close');
});
for await (const event of on(ee, 'foo', { close: ['close'] })) {
console.log(event); // prints ['bar'] [42]
}
// the loop will exit after 'close' is emitted
console.log('done'); // prints 'done'
+
+
+Optional
options: StaticEventEmitterIteratorOptionsAn AsyncIterator
that iterates eventName
events emitted by the emitter
Optional
options: StaticEventEmitterIteratorOptionsStatic
onceCreates a Promise
that is fulfilled when the EventEmitter
emits the given
+event or that is rejected if the EventEmitter
emits 'error'
while waiting.
+The Promise
will resolve with an array of all the arguments emitted to the
+given event.
This method is intentionally generic and works with the web platform EventTarget interface, which has no special'error'
event
+semantics and does not listen to the 'error'
event.
import { once, EventEmitter } from 'node:events';
import process from 'node:process';
const ee = new EventEmitter();
process.nextTick(() => {
ee.emit('myevent', 42);
});
const [value] = await once(ee, 'myevent');
console.log(value);
const err = new Error('kaboom');
process.nextTick(() => {
ee.emit('error', err);
});
try {
await once(ee, 'myevent');
} catch (err) {
console.error('error happened', err);
}
+
+
+The special handling of the 'error'
event is only used when events.once()
is used to wait for another event. If events.once()
is used to wait for the
+'error'
event itself, then it is treated as any other kind of event without
+special handling:
import { EventEmitter, once } from 'node:events';
const ee = new EventEmitter();
once(ee, 'error')
.then(([err]) => console.log('ok', err.message))
.catch((err) => console.error('error', err.message));
ee.emit('error', new Error('boom'));
// Prints: ok boom
+
+
+An AbortSignal
can be used to cancel waiting for the event:
import { EventEmitter, once } from 'node:events';
const ee = new EventEmitter();
const ac = new AbortController();
async function foo(emitter, event, signal) {
try {
await once(emitter, event, { signal });
console.log('event emitted!');
} catch (error) {
if (error.name === 'AbortError') {
console.error('Waiting for the event was canceled!');
} else {
console.error('There was an error', error.message);
}
}
}
foo(ee, 'foo', ac.signal);
ac.abort(); // Abort waiting for the event
ee.emit('foo'); // Prints: Waiting for the event was canceled!
+
+
+Optional
options: StaticEventEmitterOptionsOptional
options: StaticEventEmitterOptionsStatic
setimport { setMaxListeners, EventEmitter } from 'node:events';
const target = new EventTarget();
const emitter = new EventEmitter();
setMaxListeners(5, target, emitter);
+
+
+Optional
n: numberA non-negative number. The maximum number of listeners per EventTarget
event.
Rest
...eventTargets: (EventEmitter<DefaultEventMap> | EventTarget)[]Zero or more {EventTarget} or {EventEmitter} instances. If none are specified, n
is set as the default max for all newly created {EventTarget} and {EventEmitter}
+objects.
PokerSeat
Represents a single seat at a poker table, managing player occupancy and seat status events.
+The PokerSeat
class is central to tracking each player’s seat position, handling seat-related
+events like occupancy, vacancy, and position designation for dealer or blind roles.
PokerSeat
is designed to provide a controlled environment for managing players at individual
+seats on a poker table. It facilitates managing seat occupancy, seat status updates, and emitting
+events that alert the broader poker room to seat changes or player actions.
This class extends Node.js’s EventEmitter
, allowing PokerSeat
to emit events like
+seatOccupied
or seatVacated
to notify other components when a seat’s status changes.
This class implements PokerSeatInterface
, providing a standard interface for seat operations,
+ensuring consistent seat management across various parts of the application.
The PokerSeat
includes the following methods:
occupySeat
: Adds a player to the seat and emits a seat-occupied event.vacateSeat
: Removes the player from the seat and emits a seat-vacated event.isSeatOccupied
: Checks if the seat is currently occupied.assignBlind
: Assigns the small or big blind role to the seat.The PokerSeat
class emits events related to player actions at the seat:
This class standardizes player management at a single seat, supporting operations like setting +the dealer or blind role and monitoring seat status.
+The public constructor
method initializes a new instance of PokerSeat
, setting up its configuration based on the
+provided PokerSeatConfig
parameter. This configuration includes seat properties such as id
, position
, isDealer
,
+and the player
occupying the seat.
The constructor
method creates a fully initialized PokerSeat
instance. It provides a structure for each seat
+at a poker table and uses the __init
method to ensure all required configurations are applied.
N/A
+N/A
+config: PokerSeatConfig
- An optional configuration object that defines initial properties for the seat.
+This includes the id
, position
, isDealer
status, and the player
.config
object should be structured to align with the PokerSeatConfig
interface.config
is missing or incomplete.N/A
- As a constructor, this does not return a value.Use this constructor to create new PokerSeat
instances for each seat at a poker table, each with a unique
+configuration. This can be particularly useful when setting up multiple seats within a table class.
Configuration object for setting initial seat properties.
+Static
captureValue: boolean
+Change the default captureRejections
option on all new EventEmitter
objects.
Static
Readonly
captureValue: Symbol.for('nodejs.rejection')
See how to write a custom rejection handler
.
Static
defaultBy default, a maximum of 10
listeners can be registered for any single
+event. This limit can be changed for individual EventEmitter
instances
+using the emitter.setMaxListeners(n)
method. To change the default
+for allEventEmitter
instances, the events.defaultMaxListeners
property
+can be used. If this value is not a positive number, a RangeError
is thrown.
Take caution when setting the events.defaultMaxListeners
because the
+change affects all EventEmitter
instances, including those created before
+the change is made. However, calling emitter.setMaxListeners(n)
still has
+precedence over events.defaultMaxListeners
.
This is not a hard limit. The EventEmitter
instance will allow
+more listeners to be added but will output a trace warning to stderr indicating
+that a "possible EventEmitter memory leak" has been detected. For any single
+EventEmitter
, the emitter.getMaxListeners()
and emitter.setMaxListeners()
methods can be used to
+temporarily avoid this warning:
import { EventEmitter } from 'node:events';
const emitter = new EventEmitter();
emitter.setMaxListeners(emitter.getMaxListeners() + 1);
emitter.once('event', () => {
// do stuff
emitter.setMaxListeners(Math.max(emitter.getMaxListeners() - 1, 0));
});
+
+
+The --trace-warnings
command-line flag can be used to display the
+stack trace for such warnings.
The emitted warning can be inspected with process.on('warning')
and will
+have the additional emitter
, type
, and count
properties, referring to
+the event emitter instance, the event's name and the number of attached
+listeners, respectively.
+Its name
property is set to 'MaxListenersExceededWarning'
.
Static
Readonly
errorThis symbol shall be used to install a listener for only monitoring 'error'
events. Listeners installed using this symbol are called before the regular 'error'
listeners are called.
Installing a listener using this symbol does not change the behavior once an 'error'
event is emitted. Therefore, the process will still crash if no
+regular 'error'
listener is installed.
Optional
[captureRest
...args: AnyRestAlias for emitter.on(eventName, listener)
.
Rest
...args: any[]Synchronously calls each of the listeners registered for the event named eventName
, in the order they were registered, passing the supplied arguments
+to each.
Returns true
if the event had listeners, false
otherwise.
import { EventEmitter } from 'node:events';
const myEmitter = new EventEmitter();
// First listener
myEmitter.on('event', function firstListener() {
console.log('Helloooo! first listener');
});
// Second listener
myEmitter.on('event', function secondListener(arg1, arg2) {
console.log(`event with parameters ${arg1}, ${arg2} in second listener`);
});
// Third listener
myEmitter.on('event', function thirdListener(...args) {
const parameters = args.join(', ');
console.log(`event with parameters ${parameters} in third listener`);
});
console.log(myEmitter.listeners('event'));
myEmitter.emit('event', 1, 2, 3, 4, 5);
// Prints:
// [
// [Function: firstListener],
// [Function: secondListener],
// [Function: thirdListener]
// ]
// Helloooo! first listener
// event with parameters 1, 2 in second listener
// event with parameters 1, 2, 3, 4, 5 in third listener
+
+
+Rest
...args: AnyRestThe emitEvent
method is a public method for emitting events, with an optional configuration that allows
+middleware processing. Middleware functions can intercept and transform the event before it reaches the listeners,
+allowing custom validation or data modifications.
This method enables flexible event emission with support for middleware, providing a robust event processing
+mechanism in the BaseEventEmitter
. It’s useful for customizing event behavior based on application-specific needs.
N/A
+N/A
+This method can emit any event specified by eventName
, which can then be processed by middleware functions if defined.
eventName: string
- The name of the event to emit.options: { event: { data: { [key: string]: any }; [key: string]: any; }, middlewares?: Array<(event: BaseEventInterface, next: () => void) => void | false> }
+eventName
must be a valid string.options.event
should include relevant data for the event. If middlewares
are provided, they should be functions with an event and next parameter.void
- This method does not return a value.Use this method to emit events with middleware-based customization, which allows for specific processing +logic or transformations before the event reaches listeners.
+The name of the event to emit.
+Configuration for the event and optional middleware functions.
+Optional
middlewares?: ((event: BaseEventInterface<any>, next: (() => void)) => false | void)[]Returns an array listing the events for which the emitter has registered
+listeners. The values in the array are strings or Symbol
s.
import { EventEmitter } from 'node:events';
const myEE = new EventEmitter();
myEE.on('foo', () => {});
myEE.on('bar', () => {});
const sym = Symbol('symbol');
myEE.on(sym, () => {});
console.log(myEE.eventNames());
// Prints: [ 'foo', 'bar', Symbol(symbol) ]
+
+
+The getId
method is a public getter that retrieves the unique identifier (id
) of the PokerSeat
instance.
N/A
+N/A
+This method provides access to the unique id
of each PokerSeat
, allowing it to be referenced or compared
+with other seats at the table. This identifier is essential for managing individual seats, especially in a table
+with multiple players.
N/A
+N/A
+string
- Returns the unique identifier (id
) assigned to the seat.Use this method to retrieve the id
of the seat, which can be useful for logging, comparisons, or when tracking
+which seat a player occupies.
Returns the current max listener value for the EventEmitter
which is either
+set by emitter.setMaxListeners(n)
or defaults to defaultMaxListeners.
The getPlayer
method is a public getter that retrieves the player occupying this seat, if any.
N/A
+N/A
+This method provides access to the player currently occupying the seat, allowing the application to retrieve +player-specific data, manage player actions, or determine seat vacancy.
+N/A
+N/A
+PokerPlayerInterface | undefined
- Returns the player instance occupying this seat, or undefined
if the seat is vacant.Use this method to retrieve the player occupying this seat, which is helpful in managing player actions or +determining if the seat is available for another player.
+undefined
if vacant.The getPosition
method is a public getter that retrieves the seat’s position at the poker table.
N/A
+N/A
+This method provides access to the seat's specific position on the poker table, which is important for managing +turn order, dealer rotation, and blind assignments in poker games.
+N/A
+N/A
+number
- Returns the position of the seat at the table.Use this method to retrieve the position of the seat, which can be essential for turn-based logic and managing +seating order at the poker table.
+The isDealer
method is a public getter that checks if this seat is currently designated as the dealer seat.
N/A
+N/A
+This method indicates whether the seat has been designated as the dealer, which is critical for determining +turn order and managing the game's flow, especially in games where the dealer role rotates between players.
+N/A
+N/A
+boolean
- Returns true
if this seat is designated as the dealer, otherwise false
.Use this method to check if the seat has the dealer role, which is particularly useful for managing dealer-related +functions like initiating blinds or handling turn order.
+The isOccupied
method checks if the seat is currently occupied by a player.
This method is essential for determining seat occupancy status, enabling other parts of the program to +verify if a seat is taken before allowing actions such as seating another player.
+true
if the seat has a player, otherwise false
.Returns the number of listeners listening for the event named eventName
.
+If listener
is provided, it will return how many times the listener is found
+in the list of the listeners of the event.
The name of the event being listened for
+Optional
listener: FunctionThe event handler function
+Returns a copy of the array of listeners for the event named eventName
.
server.on('connection', (stream) => {
console.log('someone connected!');
});
console.log(util.inspect(server.listeners('connection')));
// Prints: [ [Function] ]
+
+
+The occupy
method assigns a player to occupy this seat.
This method assigns a player to the seat, indicating the seat is occupied. It is essential for seating +management, allowing a player to be seated at a specific position at the poker table.
+The player instance to assign to the seat.
+Alias for emitter.removeListener()
.
Rest
...args: any[]Adds the listener
function to the end of the listeners array for the event
+named eventName
. No checks are made to see if the listener
has already
+been added. Multiple calls passing the same combination of eventName
and
+listener
will result in the listener
being added, and called, multiple times.
server.on('connection', (stream) => {
console.log('someone connected!');
});
+
+
+Returns a reference to the EventEmitter
, so that calls can be chained.
By default, event listeners are invoked in the order they are added. The emitter.prependListener()
method can be used as an alternative to add the
+event listener to the beginning of the listeners array.
import { EventEmitter } from 'node:events';
const myEE = new EventEmitter();
myEE.on('foo', () => console.log('a'));
myEE.prependListener('foo', () => console.log('b'));
myEE.emit('foo');
// Prints:
// b
// a
+
+
+The name of the event.
+The callback function
+Rest
...args: any[]Adds a one-time listener
function for the event named eventName
. The
+next time eventName
is triggered, this listener is removed and then invoked.
server.once('connection', (stream) => {
console.log('Ah, we have our first user!');
});
+
+
+Returns a reference to the EventEmitter
, so that calls can be chained.
By default, event listeners are invoked in the order they are added. The emitter.prependOnceListener()
method can be used as an alternative to add the
+event listener to the beginning of the listeners array.
import { EventEmitter } from 'node:events';
const myEE = new EventEmitter();
myEE.once('foo', () => console.log('a'));
myEE.prependOnceListener('foo', () => console.log('b'));
myEE.emit('foo');
// Prints:
// b
// a
+
+
+The name of the event.
+The callback function
+Rest
...args: any[]Adds the listener
function to the beginning of the listeners array for the
+event named eventName
. No checks are made to see if the listener
has
+already been added. Multiple calls passing the same combination of eventName
+and listener
will result in the listener
being added, and called, multiple times.
server.prependListener('connection', (stream) => {
console.log('someone connected!');
});
+
+
+Returns a reference to the EventEmitter
, so that calls can be chained.
The name of the event.
+The callback function
+Rest
...args: any[]Adds a one-timelistener
function for the event named eventName
to the beginning of the listeners array. The next time eventName
is triggered, this
+listener is removed, and then invoked.
server.prependOnceListener('connection', (stream) => {
console.log('Ah, we have our first user!');
});
+
+
+Returns a reference to the EventEmitter
, so that calls can be chained.
The name of the event.
+The callback function
+Rest
...args: any[]Returns a copy of the array of listeners for the event named eventName
,
+including any wrappers (such as those created by .once()
).
import { EventEmitter } from 'node:events';
const emitter = new EventEmitter();
emitter.once('log', () => console.log('log once'));
// Returns a new Array with a function `onceWrapper` which has a property
// `listener` which contains the original listener bound above
const listeners = emitter.rawListeners('log');
const logFnWrapper = listeners[0];
// Logs "log once" to the console and does not unbind the `once` event
logFnWrapper.listener();
// Logs "log once" to the console and removes the listener
logFnWrapper();
emitter.on('log', () => console.log('log persistently'));
// Will return a new Array with a single function bound by `.on()` above
const newListeners = emitter.rawListeners('log');
// Logs "log persistently" twice
newListeners[0]();
emitter.emit('log');
+
+
+Removes all listeners, or those of the specified eventName
.
It is bad practice to remove listeners added elsewhere in the code,
+particularly when the EventEmitter
instance was created by some other
+component or module (e.g. sockets or file streams).
Returns a reference to the EventEmitter
, so that calls can be chained.
Optional
eventName: string | symbolRemoves the specified listener
from the listener array for the event named eventName
.
const callback = (stream) => {
console.log('someone connected!');
};
server.on('connection', callback);
// ...
server.removeListener('connection', callback);
+
+
+removeListener()
will remove, at most, one instance of a listener from the
+listener array. If any single listener has been added multiple times to the
+listener array for the specified eventName
, then removeListener()
must be
+called multiple times to remove each instance.
Once an event is emitted, all listeners attached to it at the
+time of emitting are called in order. This implies that any removeListener()
or removeAllListeners()
calls after emitting and before the last listener finishes execution
+will not remove them fromemit()
in progress. Subsequent events behave as expected.
import { EventEmitter } from 'node:events';
class MyEmitter extends EventEmitter {}
const myEmitter = new MyEmitter();
const callbackA = () => {
console.log('A');
myEmitter.removeListener('event', callbackB);
};
const callbackB = () => {
console.log('B');
};
myEmitter.on('event', callbackA);
myEmitter.on('event', callbackB);
// callbackA removes listener callbackB but it will still be called.
// Internal listener array at time of emit [callbackA, callbackB]
myEmitter.emit('event');
// Prints:
// A
// B
// callbackB is now removed.
// Internal listener array [callbackA]
myEmitter.emit('event');
// Prints:
// A
+
+
+Because listeners are managed using an internal array, calling this will
+change the position indices of any listener registered after the listener
+being removed. This will not impact the order in which listeners are called,
+but it means that any copies of the listener array as returned by
+the emitter.listeners()
method will need to be recreated.
When a single function has been added as a handler multiple times for a single
+event (as in the example below), removeListener()
will remove the most
+recently added instance. In the example the once('ping')
listener is removed:
import { EventEmitter } from 'node:events';
const ee = new EventEmitter();
function pong() {
console.log('pong');
}
ee.on('ping', pong);
ee.once('ping', pong);
ee.removeListener('ping', pong);
ee.emit('ping');
ee.emit('ping');
+
+
+Returns a reference to the EventEmitter
, so that calls can be chained.
Rest
...args: any[]The setDealer
method is a public setter that designates the PokerSeat
instance as the dealer seat if true
+is passed, or removes the dealer designation if false
is passed.
N/A
+N/A
+This method allows toggling the dealer status for a seat, which is essential for poker games where the dealer +role shifts between players. By marking a seat as the dealer, this method helps manage game flow, particularly +in the context of determining blinds, turn order, and betting phases.
+N/A
+bool: boolean
- A boolean value indicating whether this seat should be designated as the dealer.
+true
, the seat is set as the dealer.false
, the seat's dealer status is removed.bool
must be a boolean value (true
or false
).true
designates the seat as the dealer, while false
removes the dealer status.boolean
- The assigned dealer status for the seat.
+true
if the seat is designated as the dealer, and false
if it is not.Use this method to assign or remove the dealer status of a seat. Typically, only one seat at a table should +have the dealer status at any given time. This method is useful in scenarios where the dealer role rotates, +such as in each new round of a poker game.
+A boolean indicating whether this seat is the dealer.
+By default EventEmitter
s will print a warning if more than 10
listeners are
+added for a particular event. This is a useful default that helps finding
+memory leaks. The emitter.setMaxListeners()
method allows the limit to be
+modified for this specific EventEmitter
instance. The value can be set to Infinity
(or 0
) to indicate an unlimited number of listeners.
Returns a reference to the EventEmitter
, so that calls can be chained.
The vacate
method removes the player from the seat, marking it as unoccupied.
This method allows for freeing up the seat by removing the player, which is essential in poker games +where players may need to leave their seat or be reassigned to a different seat.
+Static
addExperimental
Listens once to the abort
event on the provided signal
.
Listening to the abort
event on abort signals is unsafe and may
+lead to resource leaks since another third party with the signal can
+call e.stopImmediatePropagation()
. Unfortunately Node.js cannot change
+this since it would violate the web standard. Additionally, the original
+API makes it easy to forget to remove listeners.
This API allows safely using AbortSignal
s in Node.js APIs by solving these
+two issues by listening to the event such that stopImmediatePropagation
does
+not prevent the listener from running.
Returns a disposable so that it may be unsubscribed from more easily.
+import { addAbortListener } from 'node:events';
function example(signal) {
let disposable;
try {
signal.addEventListener('abort', (e) => e.stopImmediatePropagation());
disposable = addAbortListener(signal, (e) => {
// Do something when signal is aborted.
});
} finally {
disposable?.[Symbol.dispose]();
}
}
+
+
+Disposable that removes the abort
listener.
Static
getReturns a copy of the array of listeners for the event named eventName
.
For EventEmitter
s this behaves exactly the same as calling .listeners
on
+the emitter.
For EventTarget
s this is the only way to get the event listeners for the
+event target. This is useful for debugging and diagnostic purposes.
import { getEventListeners, EventEmitter } from 'node:events';
{
const ee = new EventEmitter();
const listener = () => console.log('Events are fun');
ee.on('foo', listener);
console.log(getEventListeners(ee, 'foo')); // [ [Function: listener] ]
}
{
const et = new EventTarget();
const listener = () => console.log('Events are fun');
et.addEventListener('foo', listener);
console.log(getEventListeners(et, 'foo')); // [ [Function: listener] ]
}
+
+
+Static
getReturns the currently set max amount of listeners.
+For EventEmitter
s this behaves exactly the same as calling .getMaxListeners
on
+the emitter.
For EventTarget
s this is the only way to get the max event listeners for the
+event target. If the number of event handlers on a single EventTarget exceeds
+the max set, the EventTarget will print a warning.
import { getMaxListeners, setMaxListeners, EventEmitter } from 'node:events';
{
const ee = new EventEmitter();
console.log(getMaxListeners(ee)); // 10
setMaxListeners(11, ee);
console.log(getMaxListeners(ee)); // 11
}
{
const et = new EventTarget();
console.log(getMaxListeners(et)); // 10
setMaxListeners(11, et);
console.log(getMaxListeners(et)); // 11
}
+
+
+Static
listenerA class method that returns the number of listeners for the given eventName
registered on the given emitter
.
import { EventEmitter, listenerCount } from 'node:events';
const myEmitter = new EventEmitter();
myEmitter.on('event', () => {});
myEmitter.on('event', () => {});
console.log(listenerCount(myEmitter, 'event'));
// Prints: 2
+
+
+The emitter to query
+The event name
+Static
onimport { on, EventEmitter } from 'node:events';
import process from 'node:process';
const ee = new EventEmitter();
// Emit later on
process.nextTick(() => {
ee.emit('foo', 'bar');
ee.emit('foo', 42);
});
for await (const event of on(ee, 'foo')) {
// The execution of this inner block is synchronous and it
// processes one event at a time (even with await). Do not use
// if concurrent execution is required.
console.log(event); // prints ['bar'] [42]
}
// Unreachable here
+
+
+Returns an AsyncIterator
that iterates eventName
events. It will throw
+if the EventEmitter
emits 'error'
. It removes all listeners when
+exiting the loop. The value
returned by each iteration is an array
+composed of the emitted event arguments.
An AbortSignal
can be used to cancel waiting on events:
import { on, EventEmitter } from 'node:events';
import process from 'node:process';
const ac = new AbortController();
(async () => {
const ee = new EventEmitter();
// Emit later on
process.nextTick(() => {
ee.emit('foo', 'bar');
ee.emit('foo', 42);
});
for await (const event of on(ee, 'foo', { signal: ac.signal })) {
// The execution of this inner block is synchronous and it
// processes one event at a time (even with await). Do not use
// if concurrent execution is required.
console.log(event); // prints ['bar'] [42]
}
// Unreachable here
})();
process.nextTick(() => ac.abort());
+
+
+Use the close
option to specify an array of event names that will end the iteration:
import { on, EventEmitter } from 'node:events';
import process from 'node:process';
const ee = new EventEmitter();
// Emit later on
process.nextTick(() => {
ee.emit('foo', 'bar');
ee.emit('foo', 42);
ee.emit('close');
});
for await (const event of on(ee, 'foo', { close: ['close'] })) {
console.log(event); // prints ['bar'] [42]
}
// the loop will exit after 'close' is emitted
console.log('done'); // prints 'done'
+
+
+Optional
options: StaticEventEmitterIteratorOptionsAn AsyncIterator
that iterates eventName
events emitted by the emitter
Optional
options: StaticEventEmitterIteratorOptionsStatic
onceCreates a Promise
that is fulfilled when the EventEmitter
emits the given
+event or that is rejected if the EventEmitter
emits 'error'
while waiting.
+The Promise
will resolve with an array of all the arguments emitted to the
+given event.
This method is intentionally generic and works with the web platform EventTarget interface, which has no special'error'
event
+semantics and does not listen to the 'error'
event.
import { once, EventEmitter } from 'node:events';
import process from 'node:process';
const ee = new EventEmitter();
process.nextTick(() => {
ee.emit('myevent', 42);
});
const [value] = await once(ee, 'myevent');
console.log(value);
const err = new Error('kaboom');
process.nextTick(() => {
ee.emit('error', err);
});
try {
await once(ee, 'myevent');
} catch (err) {
console.error('error happened', err);
}
+
+
+The special handling of the 'error'
event is only used when events.once()
is used to wait for another event. If events.once()
is used to wait for the
+'error'
event itself, then it is treated as any other kind of event without
+special handling:
import { EventEmitter, once } from 'node:events';
const ee = new EventEmitter();
once(ee, 'error')
.then(([err]) => console.log('ok', err.message))
.catch((err) => console.error('error', err.message));
ee.emit('error', new Error('boom'));
// Prints: ok boom
+
+
+An AbortSignal
can be used to cancel waiting for the event:
import { EventEmitter, once } from 'node:events';
const ee = new EventEmitter();
const ac = new AbortController();
async function foo(emitter, event, signal) {
try {
await once(emitter, event, { signal });
console.log('event emitted!');
} catch (error) {
if (error.name === 'AbortError') {
console.error('Waiting for the event was canceled!');
} else {
console.error('There was an error', error.message);
}
}
}
foo(ee, 'foo', ac.signal);
ac.abort(); // Abort waiting for the event
ee.emit('foo'); // Prints: Waiting for the event was canceled!
+
+
+Optional
options: StaticEventEmitterOptionsOptional
options: StaticEventEmitterOptionsStatic
setimport { setMaxListeners, EventEmitter } from 'node:events';
const target = new EventTarget();
const emitter = new EventEmitter();
setMaxListeners(5, target, emitter);
+
+
+Optional
n: numberA non-negative number. The maximum number of listeners per EventTarget
event.
Rest
...eventTargets: (EventEmitter<DefaultEventMap> | EventTarget)[]Zero or more {EventTarget} or {EventEmitter} instances. If none are specified, n
is set as the default max for all newly created {EventTarget} and {EventEmitter}
+objects.
PokerTable
Represents a poker table within a larger casino or poker room environment. This class manages player seating, +tracks the positions of the dealer, small blind, and big blind, and coordinates the start and stop of poker games. +It includes several methods and properties to control game flow and player seating effectively.
+The PokerTable
class is central to organizing poker games within a room. It keeps track of players, manages game
+states, and ensures a smooth flow of actions at the table by overseeing betting rounds, blind assignments, and game
+progression.
This class extends the Node.js BaseEventEmitter
, enabling it to emit events for key actions such as player seating,
+game start, or game completion. This event-driven approach facilitates integration with other parts of the casino
+system, allowing external components to listen and respond to table actions.
Implements the PokerTableInterface
, ensuring a consistent structure and a clear contract for managing poker games,
+player queues, and table configuration.
The PokerTable
class includes essential methods for:
seatPlayer
, removePlayer
, getQueue
, setQueue
.startGame
, endGame
, setBlinds
.setTableConfig
, getTableConfig
, resetTable
.The PokerTable
emits events to signal key actions, including:
table:playerSeated
- Emitted when a new player is seated.table:gameStarted
- Emitted at the start of a new game.table:gameEnded
- Emitted upon game completion.This class is designed to be used within a larger poker or casino environment, providing a structured system for +managing player actions, game states, and blind assignments at a poker table. It offers methods to control various +aspects of the game and seating, making it a foundational part of managing poker tables in an organized way.
+Creates a new PokerTable
instance with configuration settings for table ID, small blind, and number of seats.
+If a configuration object is provided, it customizes the table based on this data; otherwise, default values are used.
This constructor initiates a new instance of PokerTable
, setting up basic table properties and triggering the initialization process.
config
(optional): A configuration object that includes table properties such as id
, smallBlind
, and size
.This constructor is typically called when a new table is added to a poker room, allowing optional customization for game settings.
+Optional
config: PokerTableConfigConfiguration settings for the poker table.
+Static
captureValue: boolean
+Change the default captureRejections
option on all new EventEmitter
objects.
Static
Readonly
captureValue: Symbol.for('nodejs.rejection')
See how to write a custom rejection handler
.
Static
defaultBy default, a maximum of 10
listeners can be registered for any single
+event. This limit can be changed for individual EventEmitter
instances
+using the emitter.setMaxListeners(n)
method. To change the default
+for allEventEmitter
instances, the events.defaultMaxListeners
property
+can be used. If this value is not a positive number, a RangeError
is thrown.
Take caution when setting the events.defaultMaxListeners
because the
+change affects all EventEmitter
instances, including those created before
+the change is made. However, calling emitter.setMaxListeners(n)
still has
+precedence over events.defaultMaxListeners
.
This is not a hard limit. The EventEmitter
instance will allow
+more listeners to be added but will output a trace warning to stderr indicating
+that a "possible EventEmitter memory leak" has been detected. For any single
+EventEmitter
, the emitter.getMaxListeners()
and emitter.setMaxListeners()
methods can be used to
+temporarily avoid this warning:
import { EventEmitter } from 'node:events';
const emitter = new EventEmitter();
emitter.setMaxListeners(emitter.getMaxListeners() + 1);
emitter.once('event', () => {
// do stuff
emitter.setMaxListeners(Math.max(emitter.getMaxListeners() - 1, 0));
});
+
+
+The --trace-warnings
command-line flag can be used to display the
+stack trace for such warnings.
The emitted warning can be inspected with process.on('warning')
and will
+have the additional emitter
, type
, and count
properties, referring to
+the event emitter instance, the event's name and the number of attached
+listeners, respectively.
+Its name
property is set to 'MaxListenersExceededWarning'
.
Static
Readonly
errorThis symbol shall be used to install a listener for only monitoring 'error'
events. Listeners installed using this symbol are called before the regular 'error'
listeners are called.
Installing a listener using this symbol does not change the behavior once an 'error'
event is emitted. Therefore, the process will still crash if no
+regular 'error'
listener is installed.
setSeats
Returns the poker table's id
.
The poker table's id
.
Protected
_setProtected
_setProtected
_setOptional
[captureRest
...args: AnyRestAlias for emitter.on(eventName, listener)
.
Rest
...args: any[]Synchronously calls each of the listeners registered for the event named eventName
, in the order they were registered, passing the supplied arguments
+to each.
Returns true
if the event had listeners, false
otherwise.
import { EventEmitter } from 'node:events';
const myEmitter = new EventEmitter();
// First listener
myEmitter.on('event', function firstListener() {
console.log('Helloooo! first listener');
});
// Second listener
myEmitter.on('event', function secondListener(arg1, arg2) {
console.log(`event with parameters ${arg1}, ${arg2} in second listener`);
});
// Third listener
myEmitter.on('event', function thirdListener(...args) {
const parameters = args.join(', ');
console.log(`event with parameters ${parameters} in third listener`);
});
console.log(myEmitter.listeners('event'));
myEmitter.emit('event', 1, 2, 3, 4, 5);
// Prints:
// [
// [Function: firstListener],
// [Function: secondListener],
// [Function: thirdListener]
// ]
// Helloooo! first listener
// event with parameters 1, 2 in second listener
// event with parameters 1, 2, 3, 4, 5 in third listener
+
+
+Rest
...args: AnyRestThe emitEvent
method is a public method for emitting events, with an optional configuration that allows
+middleware processing. Middleware functions can intercept and transform the event before it reaches the listeners,
+allowing custom validation or data modifications.
This method enables flexible event emission with support for middleware, providing a robust event processing
+mechanism in the BaseEventEmitter
. It’s useful for customizing event behavior based on application-specific needs.
N/A
+N/A
+This method can emit any event specified by eventName
, which can then be processed by middleware functions if defined.
eventName: string
- The name of the event to emit.options: { event: { data: { [key: string]: any }; [key: string]: any; }, middlewares?: Array<(event: BaseEventInterface, next: () => void) => void | false> }
+eventName
must be a valid string.options.event
should include relevant data for the event. If middlewares
are provided, they should be functions with an event and next parameter.void
- This method does not return a value.Use this method to emit events with middleware-based customization, which allows for specific processing +logic or transformations before the event reaches listeners.
+The name of the event to emit.
+Configuration for the event and optional middleware functions.
+Optional
middlewares?: ((event: BaseEventInterface<any>, next: (() => void)) => false | void)[]Returns an array listing the events for which the emitter has registered
+listeners. The values in the array are strings or Symbol
s.
import { EventEmitter } from 'node:events';
const myEE = new EventEmitter();
myEE.on('foo', () => {});
myEE.on('bar', () => {});
const sym = Symbol('symbol');
myEE.on(sym, () => {});
console.log(myEE.eventNames());
// Prints: [ 'foo', 'bar', Symbol(symbol) ]
+
+
+Returns the current max listener value for the EventEmitter
which is either
+set by emitter.setMaxListeners(n)
or defaults to defaultMaxListeners.
getSeats
+Starts a new PokerGame if there are at least two active players at the PokerTable.
+This method initiates the game flow, including assigning blinds and starting the rounds.
Checks if a provided index is within the valid range of the Casino’s room list.
+Implements the isValidIndex
method of CasinoInterface
.
N/A
This method helps validate that an index is within the valid bounds of the Casino’s room list. It prevents +out-of-bound errors and ensures that methods calling on rooms by index are provided with a valid reference.
+N/A
index
: A zero-based integer representing the position of a room in the Casino's managed list of rooms.index
should be a non-negative integer and within the bounds of the __rooms
array.true
if the index is within bounds.Error
if the index is out of range.Call this method before performing operations that require a valid room index to prevent out-of-bounds errors. +Can be used in any index-based access patterns for room retrieval or modification.
+The zero-based index to validate.
+true
if the index is within bounds.Returns the number of listeners listening for the event named eventName
.
+If listener
is provided, it will return how many times the listener is found
+in the list of the listeners of the event.
The name of the event being listened for
+Optional
listener: FunctionThe event handler function
+Returns a copy of the array of listeners for the event named eventName
.
server.on('connection', (stream) => {
console.log('someone connected!');
});
console.log(util.inspect(server.listeners('connection')));
// Prints: [ [Function] ]
+
+
+Alias for emitter.removeListener()
.
Rest
...args: any[]Adds the listener
function to the end of the listeners array for the event
+named eventName
. No checks are made to see if the listener
has already
+been added. Multiple calls passing the same combination of eventName
and
+listener
will result in the listener
being added, and called, multiple times.
server.on('connection', (stream) => {
console.log('someone connected!');
});
+
+
+Returns a reference to the EventEmitter
, so that calls can be chained.
By default, event listeners are invoked in the order they are added. The emitter.prependListener()
method can be used as an alternative to add the
+event listener to the beginning of the listeners array.
import { EventEmitter } from 'node:events';
const myEE = new EventEmitter();
myEE.on('foo', () => console.log('a'));
myEE.prependListener('foo', () => console.log('b'));
myEE.emit('foo');
// Prints:
// b
// a
+
+
+The name of the event.
+The callback function
+Rest
...args: any[]Adds a one-time listener
function for the event named eventName
. The
+next time eventName
is triggered, this listener is removed and then invoked.
server.once('connection', (stream) => {
console.log('Ah, we have our first user!');
});
+
+
+Returns a reference to the EventEmitter
, so that calls can be chained.
By default, event listeners are invoked in the order they are added. The emitter.prependOnceListener()
method can be used as an alternative to add the
+event listener to the beginning of the listeners array.
import { EventEmitter } from 'node:events';
const myEE = new EventEmitter();
myEE.once('foo', () => console.log('a'));
myEE.prependOnceListener('foo', () => console.log('b'));
myEE.emit('foo');
// Prints:
// b
// a
+
+
+The name of the event.
+The callback function
+Rest
...args: any[]Adds the listener
function to the beginning of the listeners array for the
+event named eventName
. No checks are made to see if the listener
has
+already been added. Multiple calls passing the same combination of eventName
+and listener
will result in the listener
being added, and called, multiple times.
server.prependListener('connection', (stream) => {
console.log('someone connected!');
});
+
+
+Returns a reference to the EventEmitter
, so that calls can be chained.
The name of the event.
+The callback function
+Rest
...args: any[]Adds a one-timelistener
function for the event named eventName
to the beginning of the listeners array. The next time eventName
is triggered, this
+listener is removed, and then invoked.
server.prependOnceListener('connection', (stream) => {
console.log('Ah, we have our first user!');
});
+
+
+Returns a reference to the EventEmitter
, so that calls can be chained.
The name of the event.
+The callback function
+Rest
...args: any[]Returns a copy of the array of listeners for the event named eventName
,
+including any wrappers (such as those created by .once()
).
import { EventEmitter } from 'node:events';
const emitter = new EventEmitter();
emitter.once('log', () => console.log('log once'));
// Returns a new Array with a function `onceWrapper` which has a property
// `listener` which contains the original listener bound above
const listeners = emitter.rawListeners('log');
const logFnWrapper = listeners[0];
// Logs "log once" to the console and does not unbind the `once` event
logFnWrapper.listener();
// Logs "log once" to the console and removes the listener
logFnWrapper();
emitter.on('log', () => console.log('log persistently'));
// Will return a new Array with a single function bound by `.on()` above
const newListeners = emitter.rawListeners('log');
// Logs "log persistently" twice
newListeners[0]();
emitter.emit('log');
+
+
+Removes all listeners, or those of the specified eventName
.
It is bad practice to remove listeners added elsewhere in the code,
+particularly when the EventEmitter
instance was created by some other
+component or module (e.g. sockets or file streams).
Returns a reference to the EventEmitter
, so that calls can be chained.
Optional
eventName: string | symbolRemoves the specified listener
from the listener array for the event named eventName
.
const callback = (stream) => {
console.log('someone connected!');
};
server.on('connection', callback);
// ...
server.removeListener('connection', callback);
+
+
+removeListener()
will remove, at most, one instance of a listener from the
+listener array. If any single listener has been added multiple times to the
+listener array for the specified eventName
, then removeListener()
must be
+called multiple times to remove each instance.
Once an event is emitted, all listeners attached to it at the
+time of emitting are called in order. This implies that any removeListener()
or removeAllListeners()
calls after emitting and before the last listener finishes execution
+will not remove them fromemit()
in progress. Subsequent events behave as expected.
import { EventEmitter } from 'node:events';
class MyEmitter extends EventEmitter {}
const myEmitter = new MyEmitter();
const callbackA = () => {
console.log('A');
myEmitter.removeListener('event', callbackB);
};
const callbackB = () => {
console.log('B');
};
myEmitter.on('event', callbackA);
myEmitter.on('event', callbackB);
// callbackA removes listener callbackB but it will still be called.
// Internal listener array at time of emit [callbackA, callbackB]
myEmitter.emit('event');
// Prints:
// A
// B
// callbackB is now removed.
// Internal listener array [callbackA]
myEmitter.emit('event');
// Prints:
// A
+
+
+Because listeners are managed using an internal array, calling this will
+change the position indices of any listener registered after the listener
+being removed. This will not impact the order in which listeners are called,
+but it means that any copies of the listener array as returned by
+the emitter.listeners()
method will need to be recreated.
When a single function has been added as a handler multiple times for a single
+event (as in the example below), removeListener()
will remove the most
+recently added instance. In the example the once('ping')
listener is removed:
import { EventEmitter } from 'node:events';
const ee = new EventEmitter();
function pong() {
console.log('pong');
}
ee.on('ping', pong);
ee.once('ping', pong);
ee.removeListener('ping', pong);
ee.emit('ping');
ee.emit('ping');
+
+
+Returns a reference to the EventEmitter
, so that calls can be chained.
Rest
...args: any[]Returns the total number of PokerRoom
instances currently managed by the Casino.
Implements the roomCount
method of CasinoInterface
.
N/A
Provides a simple way to check how many poker rooms the Casino is currently managing. Useful for general +information about the Casino's state and for validating indices or conditions that depend on room count.
+N/A
N/A
N/A
This method is useful for any scenario where the total number of active rooms is needed, such as iterating +over all rooms or validating index-based operations.
+By default EventEmitter
s will print a warning if more than 10
listeners are
+added for a particular event. This is a useful default that helps finding
+memory leaks. The emitter.setMaxListeners()
method allows the limit to be
+modified for this specific EventEmitter
instance. The value can be set to Infinity
(or 0
) to indicate an unlimited number of listeners.
Returns a reference to the EventEmitter
, so that calls can be chained.
Sets the name of the PokerRoom
, allowing the name to be updated or customized.
N/A
- This method is part of the PokerRoomInterface
and does not implement any external methods.
N/A
- This method does not override any superclass or parent methods.
The setName
method is used to assign a specific name to a PokerRoom
, which helps distinguish it within the system.
+This is essential for systems where rooms need to be identifiable and manageable through a unique name.
N/A
- No events are emitted by this method.
name
: A string representing the new name for the room. It must be a valid, non-empty string to ensure
+the room has a clear, identifiable label.name
parameter should be a non-empty string to provide meaningful identification.name
that was set for the PokerRoom
.Use this method to set or update the name of a room in a system where unique or identifiable room names +are necessary for reference.
+The new name for the PokerRoom
.
Sets the queue of players waiting to enter the PokerTable
within the PokerRoom
. This queue helps
+manage player flow and assign seating as tables become available.
N/A
- This method is part of the PokerRoomInterface
and does not implement any external methods.
N/A
- This method does not override any superclass or parent methods.
The setQueue
method provides a structured way to set or update the player queue. This queue is essential
+for room management, helping to keep a record of players awaiting entry and manage seating arrangements.
N/A
- No events are emitted by this method.
queue
: An array of PokerPlayerInterface
objects, each representing a player awaiting entry into the room’s PokerTable
.queue
should be an array of valid PokerPlayerInterface
instances.queue
array after updating it within the room.Use this method to set or update the player queue in cases where player flow needs control, +ensuring smooth transitions as players are seated at the table.
+The new list of players waiting to enter the table.
+Static
addExperimental
Listens once to the abort
event on the provided signal
.
Listening to the abort
event on abort signals is unsafe and may
+lead to resource leaks since another third party with the signal can
+call e.stopImmediatePropagation()
. Unfortunately Node.js cannot change
+this since it would violate the web standard. Additionally, the original
+API makes it easy to forget to remove listeners.
This API allows safely using AbortSignal
s in Node.js APIs by solving these
+two issues by listening to the event such that stopImmediatePropagation
does
+not prevent the listener from running.
Returns a disposable so that it may be unsubscribed from more easily.
+import { addAbortListener } from 'node:events';
function example(signal) {
let disposable;
try {
signal.addEventListener('abort', (e) => e.stopImmediatePropagation());
disposable = addAbortListener(signal, (e) => {
// Do something when signal is aborted.
});
} finally {
disposable?.[Symbol.dispose]();
}
}
+
+
+Disposable that removes the abort
listener.
Static
getReturns a copy of the array of listeners for the event named eventName
.
For EventEmitter
s this behaves exactly the same as calling .listeners
on
+the emitter.
For EventTarget
s this is the only way to get the event listeners for the
+event target. This is useful for debugging and diagnostic purposes.
import { getEventListeners, EventEmitter } from 'node:events';
{
const ee = new EventEmitter();
const listener = () => console.log('Events are fun');
ee.on('foo', listener);
console.log(getEventListeners(ee, 'foo')); // [ [Function: listener] ]
}
{
const et = new EventTarget();
const listener = () => console.log('Events are fun');
et.addEventListener('foo', listener);
console.log(getEventListeners(et, 'foo')); // [ [Function: listener] ]
}
+
+
+Static
getReturns the currently set max amount of listeners.
+For EventEmitter
s this behaves exactly the same as calling .getMaxListeners
on
+the emitter.
For EventTarget
s this is the only way to get the max event listeners for the
+event target. If the number of event handlers on a single EventTarget exceeds
+the max set, the EventTarget will print a warning.
import { getMaxListeners, setMaxListeners, EventEmitter } from 'node:events';
{
const ee = new EventEmitter();
console.log(getMaxListeners(ee)); // 10
setMaxListeners(11, ee);
console.log(getMaxListeners(ee)); // 11
}
{
const et = new EventTarget();
console.log(getMaxListeners(et)); // 10
setMaxListeners(11, et);
console.log(getMaxListeners(et)); // 11
}
+
+
+Static
listenerA class method that returns the number of listeners for the given eventName
registered on the given emitter
.
import { EventEmitter, listenerCount } from 'node:events';
const myEmitter = new EventEmitter();
myEmitter.on('event', () => {});
myEmitter.on('event', () => {});
console.log(listenerCount(myEmitter, 'event'));
// Prints: 2
+
+
+The emitter to query
+The event name
+Static
onimport { on, EventEmitter } from 'node:events';
import process from 'node:process';
const ee = new EventEmitter();
// Emit later on
process.nextTick(() => {
ee.emit('foo', 'bar');
ee.emit('foo', 42);
});
for await (const event of on(ee, 'foo')) {
// The execution of this inner block is synchronous and it
// processes one event at a time (even with await). Do not use
// if concurrent execution is required.
console.log(event); // prints ['bar'] [42]
}
// Unreachable here
+
+
+Returns an AsyncIterator
that iterates eventName
events. It will throw
+if the EventEmitter
emits 'error'
. It removes all listeners when
+exiting the loop. The value
returned by each iteration is an array
+composed of the emitted event arguments.
An AbortSignal
can be used to cancel waiting on events:
import { on, EventEmitter } from 'node:events';
import process from 'node:process';
const ac = new AbortController();
(async () => {
const ee = new EventEmitter();
// Emit later on
process.nextTick(() => {
ee.emit('foo', 'bar');
ee.emit('foo', 42);
});
for await (const event of on(ee, 'foo', { signal: ac.signal })) {
// The execution of this inner block is synchronous and it
// processes one event at a time (even with await). Do not use
// if concurrent execution is required.
console.log(event); // prints ['bar'] [42]
}
// Unreachable here
})();
process.nextTick(() => ac.abort());
+
+
+Use the close
option to specify an array of event names that will end the iteration:
import { on, EventEmitter } from 'node:events';
import process from 'node:process';
const ee = new EventEmitter();
// Emit later on
process.nextTick(() => {
ee.emit('foo', 'bar');
ee.emit('foo', 42);
ee.emit('close');
});
for await (const event of on(ee, 'foo', { close: ['close'] })) {
console.log(event); // prints ['bar'] [42]
}
// the loop will exit after 'close' is emitted
console.log('done'); // prints 'done'
+
+
+Optional
options: StaticEventEmitterIteratorOptionsAn AsyncIterator
that iterates eventName
events emitted by the emitter
Optional
options: StaticEventEmitterIteratorOptionsStatic
onceCreates a Promise
that is fulfilled when the EventEmitter
emits the given
+event or that is rejected if the EventEmitter
emits 'error'
while waiting.
+The Promise
will resolve with an array of all the arguments emitted to the
+given event.
This method is intentionally generic and works with the web platform EventTarget interface, which has no special'error'
event
+semantics and does not listen to the 'error'
event.
import { once, EventEmitter } from 'node:events';
import process from 'node:process';
const ee = new EventEmitter();
process.nextTick(() => {
ee.emit('myevent', 42);
});
const [value] = await once(ee, 'myevent');
console.log(value);
const err = new Error('kaboom');
process.nextTick(() => {
ee.emit('error', err);
});
try {
await once(ee, 'myevent');
} catch (err) {
console.error('error happened', err);
}
+
+
+The special handling of the 'error'
event is only used when events.once()
is used to wait for another event. If events.once()
is used to wait for the
+'error'
event itself, then it is treated as any other kind of event without
+special handling:
import { EventEmitter, once } from 'node:events';
const ee = new EventEmitter();
once(ee, 'error')
.then(([err]) => console.log('ok', err.message))
.catch((err) => console.error('error', err.message));
ee.emit('error', new Error('boom'));
// Prints: ok boom
+
+
+An AbortSignal
can be used to cancel waiting for the event:
import { EventEmitter, once } from 'node:events';
const ee = new EventEmitter();
const ac = new AbortController();
async function foo(emitter, event, signal) {
try {
await once(emitter, event, { signal });
console.log('event emitted!');
} catch (error) {
if (error.name === 'AbortError') {
console.error('Waiting for the event was canceled!');
} else {
console.error('There was an error', error.message);
}
}
}
foo(ee, 'foo', ac.signal);
ac.abort(); // Abort waiting for the event
ee.emit('foo'); // Prints: Waiting for the event was canceled!
+
+
+Optional
options: StaticEventEmitterOptionsOptional
options: StaticEventEmitterOptionsStatic
setimport { setMaxListeners, EventEmitter } from 'node:events';
const target = new EventTarget();
const emitter = new EventEmitter();
setMaxListeners(5, target, emitter);
+
+
+Optional
n: numberA non-negative number. The maximum number of listeners per EventTarget
event.
Rest
...eventTargets: (EventEmitter<DefaultEventMap> | EventTarget)[]Zero or more {EventTarget} or {EventEmitter} instances. If none are specified, n
is set as the default max for all newly created {EventTarget} and {EventEmitter}
+objects.
PokerPhaseName
+Defines the various phases in a standard poker game. Each phase represents a distinct stage
+within the game sequence, governing the number of community cards dealt and player actions.
PokerPhaseName
is designed to provide a clear, standardized reference for each poker phase.
+It simplifies managing the game flow and ensures that each phase can be easily referenced
+within conditional statements and game logic.
The PokerPhaseName
includes the following phases:
This enum standardizes the game flow, making it easy to transition between poker phases +and ensuring compatibility with various game modules and functions.
+The second phase where the first three community cards are dealt.
+The initial phase before any community cards are dealt.
+The fourth phase where the fifth and final community card is dealt.
+The final phase where players reveal their hands to determine the winner.
+The third phase where a fourth community card is dealt.
+CasinoEvents
+Defines the events emitted by the Casino
class for mutable operations.
+Events are triggered only for state-changing actions like creation, additions, updates, and deletions.
PokerSeatEvents
Defines the events associated with a player's seat in a poker game. These events help manage seat availability +and player actions related to occupying or vacating seats at a poker table.
+The PokerSeatEvents
enum is designed to provide a standardized reference for seat-related events in the game.
+It simplifies the handling of seat states, ensuring seat occupancy and vacancy can be tracked and updated
+accurately within the game flow.
The PokerSeatEvents
includes the following events:
This enum standardizes the handling of seat events, making it easier to manage player movements at the table and +ensuring compatibility with various game modules and event listeners.
+LogLevel
Represents the different levels of logging severity available within the library. +Each log level corresponds to a specific type of message, providing clarity on the nature and urgency of the log. +The levels are structured to allow for selective filtering based on severity and importance.
+The LogLevel
enum standardizes log severity levels, ensuring that log messages are consistently categorized.
+This approach aids in debugging, monitoring, and organizing log data by its importance, making it easier to parse
+and filter through logs in development, production, or auditing scenarios.
The LogLevel
enum is used across the logging system to specify the severity of each log message. It includes:
Rank
+Represents the ranks of playing cards used in poker.
+Each rank corresponds to a specific card value from 2 to Ace.
Source
+Defines the sources of various components and entities within the library, each representing a specific
+entity or module that can emit events or interact within the system. This enum is used as a standardized
+identifier for the origin of actions, events, or data across the library.
Source
is designed to standardize the identification of each module or entity within the library,
+facilitating tracing, logging, and debugging. Each value corresponds to a distinct source, making it
+clear where specific events or actions originate.
BaseEventEmitter
, the foundational emitter for events within the library.Card
model, corresponding to individual playing cards in the library.Casino
model, handling high-level operations related to game management.Deck
, representing a collection or set of cards in a game context.PokerGame
model, managing game-specific actions and states.PokerPhase
model, indicating the stages or phases within a poker game.PokerPlayer
model, encompassing player-specific data and actions.PokerRoom
model, representing rooms where games take place.PokerSeat
model, representing individual seats within a poker table.PokerTable
model, handling table-specific settings and seating.Source
provides a standard set of identifiers used across the library for event emission and origin
+tracking. Each entity or module can reference its corresponding Source
value when emitting events or
+logging actions, enhancing traceability and modularity.
Represents the BaseEventEmitter
, the foundational event emitter for the library.
Represents the Card
model, corresponding to individual playing cards.
Refers to the Casino
model, which handles casino or game management operations.
Identifies the Deck
, representing a collection of playing cards.
Corresponds to the PokerGame
model, responsible for managing the poker game actions and states.
Represents the PokerPhase
model, indicating stages or phases within a poker game.
Refers to the PokerPlayer
model, encompassing player-specific data and actions.
Corresponds to the PokerRoom
model, representing rooms where games take place.
Refers to the PokerSeat
model, representing individual seats within a poker table.
Represents the PokerTable
model, which handles table-specific settings and seating.
Suit
+Represents the suits of playing cards used in poker.
+Each suit corresponds to one of the four card suits: Hearts, Diamonds, Clubs, and Spades.
nodejs-project-template
+CasinoJs
For more detailed information, please refer to the full contribution guidelines.
-BaseEventEmitterInterface +Extends the standard Node.js EventEmitter, including listener management methods.
+Optional
[captureRest
...args: AnyRestAlias for emitter.on(eventName, listener)
.
Rest
...args: any[]Synchronously calls each of the listeners registered for the event named eventName
, in the order they were registered, passing the supplied arguments
+to each.
Returns true
if the event had listeners, false
otherwise.
import { EventEmitter } from 'node:events';
const myEmitter = new EventEmitter();
// First listener
myEmitter.on('event', function firstListener() {
console.log('Helloooo! first listener');
});
// Second listener
myEmitter.on('event', function secondListener(arg1, arg2) {
console.log(`event with parameters ${arg1}, ${arg2} in second listener`);
});
// Third listener
myEmitter.on('event', function thirdListener(...args) {
const parameters = args.join(', ');
console.log(`event with parameters ${parameters} in third listener`);
});
console.log(myEmitter.listeners('event'));
myEmitter.emit('event', 1, 2, 3, 4, 5);
// Prints:
// [
// [Function: firstListener],
// [Function: secondListener],
// [Function: thirdListener]
// ]
// Helloooo! first listener
// event with parameters 1, 2 in second listener
// event with parameters 1, 2, 3, 4, 5 in third listener
+
+
+Rest
...args: AnyRestReturns an array listing the events for which the emitter has registered
+listeners. The values in the array are strings or Symbol
s.
import { EventEmitter } from 'node:events';
const myEE = new EventEmitter();
myEE.on('foo', () => {});
myEE.on('bar', () => {});
const sym = Symbol('symbol');
myEE.on(sym, () => {});
console.log(myEE.eventNames());
// Prints: [ 'foo', 'bar', Symbol(symbol) ]
+
+
+Returns the number of listeners listening for the event named eventName
.
+If listener
is provided, it will return how many times the listener is found
+in the list of the listeners of the event.
The name of the event being listened for
+Optional
listener: FunctionThe event handler function
+Returns a copy of the array of listeners for the event named eventName
.
server.on('connection', (stream) => {
console.log('someone connected!');
});
console.log(util.inspect(server.listeners('connection')));
// Prints: [ [Function] ]
+
+
+Alias for emitter.removeListener()
.
Rest
...args: any[]Adds the listener
function to the end of the listeners array for the event
+named eventName
. No checks are made to see if the listener
has already
+been added. Multiple calls passing the same combination of eventName
and
+listener
will result in the listener
being added, and called, multiple times.
server.on('connection', (stream) => {
console.log('someone connected!');
});
+
+
+Returns a reference to the EventEmitter
, so that calls can be chained.
By default, event listeners are invoked in the order they are added. The emitter.prependListener()
method can be used as an alternative to add the
+event listener to the beginning of the listeners array.
import { EventEmitter } from 'node:events';
const myEE = new EventEmitter();
myEE.on('foo', () => console.log('a'));
myEE.prependListener('foo', () => console.log('b'));
myEE.emit('foo');
// Prints:
// b
// a
+
+
+The name of the event.
+The callback function
+Rest
...args: any[]Adds a one-time listener
function for the event named eventName
. The
+next time eventName
is triggered, this listener is removed and then invoked.
server.once('connection', (stream) => {
console.log('Ah, we have our first user!');
});
+
+
+Returns a reference to the EventEmitter
, so that calls can be chained.
By default, event listeners are invoked in the order they are added. The emitter.prependOnceListener()
method can be used as an alternative to add the
+event listener to the beginning of the listeners array.
import { EventEmitter } from 'node:events';
const myEE = new EventEmitter();
myEE.once('foo', () => console.log('a'));
myEE.prependOnceListener('foo', () => console.log('b'));
myEE.emit('foo');
// Prints:
// b
// a
+
+
+The name of the event.
+The callback function
+Rest
...args: any[]Adds the listener
function to the beginning of the listeners array for the
+event named eventName
. No checks are made to see if the listener
has
+already been added. Multiple calls passing the same combination of eventName
+and listener
will result in the listener
being added, and called, multiple times.
server.prependListener('connection', (stream) => {
console.log('someone connected!');
});
+
+
+Returns a reference to the EventEmitter
, so that calls can be chained.
The name of the event.
+The callback function
+Rest
...args: any[]Adds a one-timelistener
function for the event named eventName
to the beginning of the listeners array. The next time eventName
is triggered, this
+listener is removed, and then invoked.
server.prependOnceListener('connection', (stream) => {
console.log('Ah, we have our first user!');
});
+
+
+Returns a reference to the EventEmitter
, so that calls can be chained.
The name of the event.
+The callback function
+Rest
...args: any[]Returns a copy of the array of listeners for the event named eventName
,
+including any wrappers (such as those created by .once()
).
import { EventEmitter } from 'node:events';
const emitter = new EventEmitter();
emitter.once('log', () => console.log('log once'));
// Returns a new Array with a function `onceWrapper` which has a property
// `listener` which contains the original listener bound above
const listeners = emitter.rawListeners('log');
const logFnWrapper = listeners[0];
// Logs "log once" to the console and does not unbind the `once` event
logFnWrapper.listener();
// Logs "log once" to the console and removes the listener
logFnWrapper();
emitter.on('log', () => console.log('log persistently'));
// Will return a new Array with a single function bound by `.on()` above
const newListeners = emitter.rawListeners('log');
// Logs "log persistently" twice
newListeners[0]();
emitter.emit('log');
+
+
+Removes all listeners, or those of the specified eventName
.
It is bad practice to remove listeners added elsewhere in the code,
+particularly when the EventEmitter
instance was created by some other
+component or module (e.g. sockets or file streams).
Returns a reference to the EventEmitter
, so that calls can be chained.
Optional
eventName: string | symbolRemoves the specified listener
from the listener array for the event named eventName
.
const callback = (stream) => {
console.log('someone connected!');
};
server.on('connection', callback);
// ...
server.removeListener('connection', callback);
+
+
+removeListener()
will remove, at most, one instance of a listener from the
+listener array. If any single listener has been added multiple times to the
+listener array for the specified eventName
, then removeListener()
must be
+called multiple times to remove each instance.
Once an event is emitted, all listeners attached to it at the
+time of emitting are called in order. This implies that any removeListener()
or removeAllListeners()
calls after emitting and before the last listener finishes execution
+will not remove them fromemit()
in progress. Subsequent events behave as expected.
import { EventEmitter } from 'node:events';
class MyEmitter extends EventEmitter {}
const myEmitter = new MyEmitter();
const callbackA = () => {
console.log('A');
myEmitter.removeListener('event', callbackB);
};
const callbackB = () => {
console.log('B');
};
myEmitter.on('event', callbackA);
myEmitter.on('event', callbackB);
// callbackA removes listener callbackB but it will still be called.
// Internal listener array at time of emit [callbackA, callbackB]
myEmitter.emit('event');
// Prints:
// A
// B
// callbackB is now removed.
// Internal listener array [callbackA]
myEmitter.emit('event');
// Prints:
// A
+
+
+Because listeners are managed using an internal array, calling this will
+change the position indices of any listener registered after the listener
+being removed. This will not impact the order in which listeners are called,
+but it means that any copies of the listener array as returned by
+the emitter.listeners()
method will need to be recreated.
When a single function has been added as a handler multiple times for a single
+event (as in the example below), removeListener()
will remove the most
+recently added instance. In the example the once('ping')
listener is removed:
import { EventEmitter } from 'node:events';
const ee = new EventEmitter();
function pong() {
console.log('pong');
}
ee.on('ping', pong);
ee.once('ping', pong);
ee.removeListener('ping', pong);
ee.emit('ping');
ee.emit('ping');
+
+
+Returns a reference to the EventEmitter
, so that calls can be chained.
Rest
...args: any[]By default EventEmitter
s will print a warning if more than 10
listeners are
+added for a particular event. This is a useful default that helps finding
+memory leaks. The emitter.setMaxListeners()
method allows the limit to be
+modified for this specific EventEmitter
instance. The value can be set to Infinity
(or 0
) to indicate an unlimited number of listeners.
Returns a reference to the EventEmitter
, so that calls can be chained.
BaseEventInterface
Represents a foundational structure for events emitted within the library, ensuring consistency +across event types by standardizing metadata and event-specific payload sections.
+The BaseEventInterface
interface establishes a uniform format for all events within the library, promoting
+a cohesive structure for both general event metadata and customizable data content. Designed for flexibility,
+BaseEventInterface
can be extended by more specific event types, allowing for additional properties as needed
+by various components of the library.
id
, name
, source
, and optional fields like status
and priority
+allow for tracking and categorizing events effectively.BaseEventInterface
provides a structured foundation for defining library-wide events. It can be extended by
+event-specific interfaces that introduce additional data fields. This makes BaseEventInterface
a versatile
+base for a variety of events while ensuring a consistent structure across the library.
const event: BaseEventInterface = {
id: "unique-id-1234",
name: "Casino:RoomCreated",
source: "PokerRoom",
createdAt: new Date(),
data: { customData: "event-specific details" },
priority: 1,
customField: "extra info"
};
console.log(event);
// Console Output: { id: "unique-id-1234", name: "Casino:RoomCreated", source: "PokerRoom", createdAt: <Date>, data: { customData: "event-specific details" }, priority: 1, customField: "extra info" }
+
+
+CardInterface
+Represents the structure of a card in a poker game.
+The interface provides methods to retrieve the card's rank, suit, and other related details.
ICard
-Represents the structure of a card in a poker game.
CasinoInterface
+Represents the core responsibilities and structure of a Casino entity within the system. It manages multiple PokerRoom
instances and facilitates the organization of poker games through room creation, player allocation, and game tracking.
The CasinoInterface
serves as a blueprint for any Casino
class that manages multiple poker rooms. It defines room management methods, player allocation functions, and potentially methods for tracking player statistics or games across rooms.
This interface extends NodeJS.EventEmitter
to emit events associated with key actions, such as room creation or removal, enhancing flexibility in managing event-driven operations across the Casino system.
The CasinoInterface
includes essential methods to:
The CasinoInterface
supports event emissions for room-related actions. Events allow other parts of the application to subscribe to changes in the Casino, making it easier to handle notifications and updates.
Optional
[captureRest
...args: AnyRestAlias for emitter.on(eventName, listener)
.
Rest
...args: any[]Adds a new PokerRoom
instance to the Casino's list of managed rooms, enabling dynamic expansion
+of rooms within the Casino environment.
N/A
N/A
This method provides a flexible mechanism for expanding the Casino's room offerings by allowing new +rooms to be added as required, thereby supporting various gaming scenarios and player demand.
+N/A
room
- A PokerRoomInterface
instance representing the room to be added to the Casino’s list.room
parameter must be a valid instance implementing PokerRoomInterface
.true
to confirm that the room has been successfully added to the Casino.Typically used in scenarios where the Casino environment needs to expand by adding more gaming rooms.
+The PokerRoom
instance to add.
true
when the room has been added successfully.Adds a new PokerRoom
instance to the Casino's list of managed rooms, enabling dynamic expansion
+of rooms within the Casino environment.
N/A
N/A
This method provides a flexible mechanism for expanding the Casino's room offerings by allowing new +rooms to be added as required, thereby supporting various gaming scenarios and player demand.
+N/A
room
- A PokerRoomInterface
instance representing the room to be added to the Casino’s list.room
parameter must be a valid instance implementing PokerRoomInterface
.true
to confirm that the room has been successfully added to the Casino.Typically used in scenarios where the Casino environment needs to expand by adding more gaming rooms.
+The PokerRoom
instance to add.
true
when the room has been added successfully.Creates a new PokerRoom
within the Casino and adds it to the list of rooms.
Implements the createRoom
method of CasinoInterface
.
N/A
Enables the dynamic creation and addition of a PokerRoom
to the Casino, expanding the Casino’s managed rooms as required.
+This facilitates flexible game setup and room management in response to user needs.
casino:roomCreated
: This custom event is emitted once the room is successfully added.
+Listeners to this event can respond with actions, such as logging or notifying users.config
: A configuration object containing details like the room’s name, table size, small blind, and big blind values.name
, tableSize
, smallBlind
, and bigBlind
.PokerRoom
instance, confirming its addition to the Casino.This method creates a new room based on the provided configuration, then pushes it into the Casino’s room list.
+After adding the room, it emits a casino:roomCreated
event for any listeners tracking room creation.
A configuration object with properties like the room name, table size, small blind, and big blind values.
+PokerRoom
instance.Removes a PokerRoom
from the Casino's list of managed rooms based on the room's name, enabling dynamic
+contraction of the Casino environment as required.
N/A
N/A
Allows the Casino environment to remain current by dynamically removing rooms that are no longer active +or needed. This supports a clean and manageable set of active rooms within the Casino.
+casino:roomRemoved
event when a room is successfully removed. This event can be used
+to trigger updates, logging, or notifications.roomName
: A string representing the name of the PokerRoom
to be removed from the Casino.roomName
parameter should match the name
property of an existing room for successful deletion.true
if the room was successfully removed, or false
if no room with the specified name was found.Use this method when removing a room that is no longer active or required, ensuring that only +currently used rooms remain managed by the Casino.
+The name of the PokerRoom
to be removed.
true
if the room was removed; false
if not found.Synchronously calls each of the listeners registered for the event named eventName
, in the order they were registered, passing the supplied arguments
+to each.
Returns true
if the event had listeners, false
otherwise.
import { EventEmitter } from 'node:events';
const myEmitter = new EventEmitter();
// First listener
myEmitter.on('event', function firstListener() {
console.log('Helloooo! first listener');
});
// Second listener
myEmitter.on('event', function secondListener(arg1, arg2) {
console.log(`event with parameters ${arg1}, ${arg2} in second listener`);
});
// Third listener
myEmitter.on('event', function thirdListener(...args) {
const parameters = args.join(', ');
console.log(`event with parameters ${parameters} in third listener`);
});
console.log(myEmitter.listeners('event'));
myEmitter.emit('event', 1, 2, 3, 4, 5);
// Prints:
// [
// [Function: firstListener],
// [Function: secondListener],
// [Function: thirdListener]
// ]
// Helloooo! first listener
// event with parameters 1, 2 in second listener
// event with parameters 1, 2, 3, 4, 5 in third listener
+
+
+Rest
...args: AnyRestReturns an array listing the events for which the emitter has registered
+listeners. The values in the array are strings or Symbol
s.
import { EventEmitter } from 'node:events';
const myEE = new EventEmitter();
myEE.on('foo', () => {});
myEE.on('bar', () => {});
const sym = Symbol('symbol');
myEE.on(sym, () => {});
console.log(myEE.eventNames());
// Prints: [ 'foo', 'bar', Symbol(symbol) ]
+
+
+Retrieves a specific PokerRoom
based on its position within the Casino’s list of rooms.
N/A
N/A
This method provides direct access to a single PokerRoom
by index, allowing for targeted retrieval of rooms,
+which can be useful for room-specific operations or when sequentially processing rooms.
N/A
index
: A zero-based index representing the position of the desired PokerRoom
in the Casino’s room list.__rooms
array (i.e., 0 <= index < __rooms.length
).undefined
return.PokerRoomInterface
instance located at the specified index.undefined
if the provided index is out of bounds.Use this method when you need to access a particular room directly by its index in the Casino’s list of rooms. +This can be useful in looped operations or when accessing rooms based on their position in the list.
+The zero-based index of the desired room in the Casino’s room list.
+PokerRoom
at the specified index or undefined
if the index is out of bounds.Retrieves the full list of rooms currently managed by the Casino.
+Implements the getRooms
method of CasinoInterface
.
N/A
Provides access to the Casino's list of rooms, allowing external components or systems to retrieve and display +information on all currently managed poker rooms.
+N/A
N/A
N/A
PokerRoomInterface
instances currently managed by the Casino.This method is useful when a complete list of active rooms is needed, such as when displaying the Casino's +available games or managing room states.
+PokerRoom
objects in the Casino.Validates if a specified index is within the valid bounds of the Casino’s room list.
+N/A
N/A
Prevents out-of-bounds errors by confirming that an index is within the acceptable range for the Casino’s +room list, ensuring that subsequent calls to access rooms by index have a valid target.
+N/A
index
: A zero-based integer specifying the position of a room within the Casino's managed room list.index
must be a non-negative integer within the bounds of the __rooms
array.true
if the index is within bounds.Error
if the index is out of bounds.Call this method before performing operations involving indexed access to rooms, ensuring the index +falls within valid boundaries.
+The zero-based index to validate within the room list.
+true
if the index is within bounds.Returns the number of listeners listening for the event named eventName
.
+If listener
is provided, it will return how many times the listener is found
+in the list of the listeners of the event.
The name of the event being listened for
+Optional
listener: FunctionThe event handler function
+Returns a copy of the array of listeners for the event named eventName
.
server.on('connection', (stream) => {
console.log('someone connected!');
});
console.log(util.inspect(server.listeners('connection')));
// Prints: [ [Function] ]
+
+
+Alias for emitter.removeListener()
.
Rest
...args: any[]Adds the listener
function to the end of the listeners array for the event
+named eventName
. No checks are made to see if the listener
has already
+been added. Multiple calls passing the same combination of eventName
and
+listener
will result in the listener
being added, and called, multiple times.
server.on('connection', (stream) => {
console.log('someone connected!');
});
+
+
+Returns a reference to the EventEmitter
, so that calls can be chained.
By default, event listeners are invoked in the order they are added. The emitter.prependListener()
method can be used as an alternative to add the
+event listener to the beginning of the listeners array.
import { EventEmitter } from 'node:events';
const myEE = new EventEmitter();
myEE.on('foo', () => console.log('a'));
myEE.prependListener('foo', () => console.log('b'));
myEE.emit('foo');
// Prints:
// b
// a
+
+
+The name of the event.
+The callback function
+Rest
...args: any[]Adds a one-time listener
function for the event named eventName
. The
+next time eventName
is triggered, this listener is removed and then invoked.
server.once('connection', (stream) => {
console.log('Ah, we have our first user!');
});
+
+
+Returns a reference to the EventEmitter
, so that calls can be chained.
By default, event listeners are invoked in the order they are added. The emitter.prependOnceListener()
method can be used as an alternative to add the
+event listener to the beginning of the listeners array.
import { EventEmitter } from 'node:events';
const myEE = new EventEmitter();
myEE.once('foo', () => console.log('a'));
myEE.prependOnceListener('foo', () => console.log('b'));
myEE.emit('foo');
// Prints:
// b
// a
+
+
+The name of the event.
+The callback function
+Rest
...args: any[]Adds the listener
function to the beginning of the listeners array for the
+event named eventName
. No checks are made to see if the listener
has
+already been added. Multiple calls passing the same combination of eventName
+and listener
will result in the listener
being added, and called, multiple times.
server.prependListener('connection', (stream) => {
console.log('someone connected!');
});
+
+
+Returns a reference to the EventEmitter
, so that calls can be chained.
The name of the event.
+The callback function
+Rest
...args: any[]Adds a one-timelistener
function for the event named eventName
to the beginning of the listeners array. The next time eventName
is triggered, this
+listener is removed, and then invoked.
server.prependOnceListener('connection', (stream) => {
console.log('Ah, we have our first user!');
});
+
+
+Returns a reference to the EventEmitter
, so that calls can be chained.
The name of the event.
+The callback function
+Rest
...args: any[]Returns a copy of the array of listeners for the event named eventName
,
+including any wrappers (such as those created by .once()
).
import { EventEmitter } from 'node:events';
const emitter = new EventEmitter();
emitter.once('log', () => console.log('log once'));
// Returns a new Array with a function `onceWrapper` which has a property
// `listener` which contains the original listener bound above
const listeners = emitter.rawListeners('log');
const logFnWrapper = listeners[0];
// Logs "log once" to the console and does not unbind the `once` event
logFnWrapper.listener();
// Logs "log once" to the console and removes the listener
logFnWrapper();
emitter.on('log', () => console.log('log persistently'));
// Will return a new Array with a single function bound by `.on()` above
const newListeners = emitter.rawListeners('log');
// Logs "log persistently" twice
newListeners[0]();
emitter.emit('log');
+
+
+Removes all listeners, or those of the specified eventName
.
It is bad practice to remove listeners added elsewhere in the code,
+particularly when the EventEmitter
instance was created by some other
+component or module (e.g. sockets or file streams).
Returns a reference to the EventEmitter
, so that calls can be chained.
Optional
eventName: string | symbolRemoves the specified listener
from the listener array for the event named eventName
.
const callback = (stream) => {
console.log('someone connected!');
};
server.on('connection', callback);
// ...
server.removeListener('connection', callback);
+
+
+removeListener()
will remove, at most, one instance of a listener from the
+listener array. If any single listener has been added multiple times to the
+listener array for the specified eventName
, then removeListener()
must be
+called multiple times to remove each instance.
Once an event is emitted, all listeners attached to it at the
+time of emitting are called in order. This implies that any removeListener()
or removeAllListeners()
calls after emitting and before the last listener finishes execution
+will not remove them fromemit()
in progress. Subsequent events behave as expected.
import { EventEmitter } from 'node:events';
class MyEmitter extends EventEmitter {}
const myEmitter = new MyEmitter();
const callbackA = () => {
console.log('A');
myEmitter.removeListener('event', callbackB);
};
const callbackB = () => {
console.log('B');
};
myEmitter.on('event', callbackA);
myEmitter.on('event', callbackB);
// callbackA removes listener callbackB but it will still be called.
// Internal listener array at time of emit [callbackA, callbackB]
myEmitter.emit('event');
// Prints:
// A
// B
// callbackB is now removed.
// Internal listener array [callbackA]
myEmitter.emit('event');
// Prints:
// A
+
+
+Because listeners are managed using an internal array, calling this will
+change the position indices of any listener registered after the listener
+being removed. This will not impact the order in which listeners are called,
+but it means that any copies of the listener array as returned by
+the emitter.listeners()
method will need to be recreated.
When a single function has been added as a handler multiple times for a single
+event (as in the example below), removeListener()
will remove the most
+recently added instance. In the example the once('ping')
listener is removed:
import { EventEmitter } from 'node:events';
const ee = new EventEmitter();
function pong() {
console.log('pong');
}
ee.on('ping', pong);
ee.once('ping', pong);
ee.removeListener('ping', pong);
ee.emit('ping');
ee.emit('ping');
+
+
+Returns a reference to the EventEmitter
, so that calls can be chained.
Rest
...args: any[]Retrieves the total number of PokerRoom
instances currently managed by the Casino.
N/A
N/A
This method provides insight into the number of poker rooms that the Casino manages, supporting +validation for index-bound operations or general information on Casino state.
+N/A
N/A
N/A
Use this method to retrieve the total count of active poker rooms, which is helpful when iterating over +rooms or confirming index-bound conditions.
+By default EventEmitter
s will print a warning if more than 10
listeners are
+added for a particular event. This is a useful default that helps finding
+memory leaks. The emitter.setMaxListeners()
method allows the limit to be
+modified for this specific EventEmitter
instance. The value can be set to Infinity
(or 0
) to indicate an unlimited number of listeners.
Returns a reference to the EventEmitter
, so that calls can be chained.
Sets the list of rooms managed by the Casino. This method is typically used to replace or update +the entire list of poker rooms in the casino.
+Implements the setRooms
method of CasinoInterface
.
N/A
Provides a way to update the current list of rooms managed by the Casino, ensuring a consistent and up-to-date +list of poker rooms as defined by the casino’s configuration.
+N/A
: No event
is emitted by this method.rooms
: An array of PokerRoomInterface
instances, representing individual poker rooms in the Casino.rooms
array must contain at least one room (i.e., rooms.length >= 1
).true
when the rooms have been successfully set.This method accepts an array of PokerRoomInterface
objects, representing poker rooms to manage in the casino.
__setRooms
method to update the private __rooms
property securely.The new list of poker rooms to be managed by the Casino.
+true
when the rooms have been successfully set.DeckInterface
+Represents the structure of a deck in a poker game.
+The interface provides methods to shuffle the deck and draw cards from the top.
Optional
[captureRest
...args: AnyRestAlias for emitter.on(eventName, listener)
.
Rest
...args: any[]draw
+Draws a card from the top of the deck.
Returns the drawn card or undefined
if no cards remain.
Synchronously calls each of the listeners registered for the event named eventName
, in the order they were registered, passing the supplied arguments
+to each.
Returns true
if the event had listeners, false
otherwise.
import { EventEmitter } from 'node:events';
const myEmitter = new EventEmitter();
// First listener
myEmitter.on('event', function firstListener() {
console.log('Helloooo! first listener');
});
// Second listener
myEmitter.on('event', function secondListener(arg1, arg2) {
console.log(`event with parameters ${arg1}, ${arg2} in second listener`);
});
// Third listener
myEmitter.on('event', function thirdListener(...args) {
const parameters = args.join(', ');
console.log(`event with parameters ${parameters} in third listener`);
});
console.log(myEmitter.listeners('event'));
myEmitter.emit('event', 1, 2, 3, 4, 5);
// Prints:
// [
// [Function: firstListener],
// [Function: secondListener],
// [Function: thirdListener]
// ]
// Helloooo! first listener
// event with parameters 1, 2 in second listener
// event with parameters 1, 2, 3, 4, 5 in third listener
+
+
+Rest
...args: AnyRestReturns an array listing the events for which the emitter has registered
+listeners. The values in the array are strings or Symbol
s.
import { EventEmitter } from 'node:events';
const myEE = new EventEmitter();
myEE.on('foo', () => {});
myEE.on('bar', () => {});
const sym = Symbol('symbol');
myEE.on(sym, () => {});
console.log(myEE.eventNames());
// Prints: [ 'foo', 'bar', Symbol(symbol) ]
+
+
+READ METHODS (GETTERS & DATA RETRIEVAL)
+Returns the number of listeners listening for the event named eventName
.
+If listener
is provided, it will return how many times the listener is found
+in the list of the listeners of the event.
The name of the event being listened for
+Optional
listener: FunctionThe event handler function
+Returns a copy of the array of listeners for the event named eventName
.
server.on('connection', (stream) => {
console.log('someone connected!');
});
console.log(util.inspect(server.listeners('connection')));
// Prints: [ [Function] ]
+
+
+Alias for emitter.removeListener()
.
Rest
...args: any[]Adds the listener
function to the end of the listeners array for the event
+named eventName
. No checks are made to see if the listener
has already
+been added. Multiple calls passing the same combination of eventName
and
+listener
will result in the listener
being added, and called, multiple times.
server.on('connection', (stream) => {
console.log('someone connected!');
});
+
+
+Returns a reference to the EventEmitter
, so that calls can be chained.
By default, event listeners are invoked in the order they are added. The emitter.prependListener()
method can be used as an alternative to add the
+event listener to the beginning of the listeners array.
import { EventEmitter } from 'node:events';
const myEE = new EventEmitter();
myEE.on('foo', () => console.log('a'));
myEE.prependListener('foo', () => console.log('b'));
myEE.emit('foo');
// Prints:
// b
// a
+
+
+The name of the event.
+The callback function
+Rest
...args: any[]Adds a one-time listener
function for the event named eventName
. The
+next time eventName
is triggered, this listener is removed and then invoked.
server.once('connection', (stream) => {
console.log('Ah, we have our first user!');
});
+
+
+Returns a reference to the EventEmitter
, so that calls can be chained.
By default, event listeners are invoked in the order they are added. The emitter.prependOnceListener()
method can be used as an alternative to add the
+event listener to the beginning of the listeners array.
import { EventEmitter } from 'node:events';
const myEE = new EventEmitter();
myEE.once('foo', () => console.log('a'));
myEE.prependOnceListener('foo', () => console.log('b'));
myEE.emit('foo');
// Prints:
// b
// a
+
+
+The name of the event.
+The callback function
+Rest
...args: any[]Adds the listener
function to the beginning of the listeners array for the
+event named eventName
. No checks are made to see if the listener
has
+already been added. Multiple calls passing the same combination of eventName
+and listener
will result in the listener
being added, and called, multiple times.
server.prependListener('connection', (stream) => {
console.log('someone connected!');
});
+
+
+Returns a reference to the EventEmitter
, so that calls can be chained.
The name of the event.
+The callback function
+Rest
...args: any[]Adds a one-timelistener
function for the event named eventName
to the beginning of the listeners array. The next time eventName
is triggered, this
+listener is removed, and then invoked.
server.prependOnceListener('connection', (stream) => {
console.log('Ah, we have our first user!');
});
+
+
+Returns a reference to the EventEmitter
, so that calls can be chained.
The name of the event.
+The callback function
+Rest
...args: any[]Returns a copy of the array of listeners for the event named eventName
,
+including any wrappers (such as those created by .once()
).
import { EventEmitter } from 'node:events';
const emitter = new EventEmitter();
emitter.once('log', () => console.log('log once'));
// Returns a new Array with a function `onceWrapper` which has a property
// `listener` which contains the original listener bound above
const listeners = emitter.rawListeners('log');
const logFnWrapper = listeners[0];
// Logs "log once" to the console and does not unbind the `once` event
logFnWrapper.listener();
// Logs "log once" to the console and removes the listener
logFnWrapper();
emitter.on('log', () => console.log('log persistently'));
// Will return a new Array with a single function bound by `.on()` above
const newListeners = emitter.rawListeners('log');
// Logs "log persistently" twice
newListeners[0]();
emitter.emit('log');
+
+
+Removes all listeners, or those of the specified eventName
.
It is bad practice to remove listeners added elsewhere in the code,
+particularly when the EventEmitter
instance was created by some other
+component or module (e.g. sockets or file streams).
Returns a reference to the EventEmitter
, so that calls can be chained.
Optional
eventName: string | symbolRemoves the specified listener
from the listener array for the event named eventName
.
const callback = (stream) => {
console.log('someone connected!');
};
server.on('connection', callback);
// ...
server.removeListener('connection', callback);
+
+
+removeListener()
will remove, at most, one instance of a listener from the
+listener array. If any single listener has been added multiple times to the
+listener array for the specified eventName
, then removeListener()
must be
+called multiple times to remove each instance.
Once an event is emitted, all listeners attached to it at the
+time of emitting are called in order. This implies that any removeListener()
or removeAllListeners()
calls after emitting and before the last listener finishes execution
+will not remove them fromemit()
in progress. Subsequent events behave as expected.
import { EventEmitter } from 'node:events';
class MyEmitter extends EventEmitter {}
const myEmitter = new MyEmitter();
const callbackA = () => {
console.log('A');
myEmitter.removeListener('event', callbackB);
};
const callbackB = () => {
console.log('B');
};
myEmitter.on('event', callbackA);
myEmitter.on('event', callbackB);
// callbackA removes listener callbackB but it will still be called.
// Internal listener array at time of emit [callbackA, callbackB]
myEmitter.emit('event');
// Prints:
// A
// B
// callbackB is now removed.
// Internal listener array [callbackA]
myEmitter.emit('event');
// Prints:
// A
+
+
+Because listeners are managed using an internal array, calling this will
+change the position indices of any listener registered after the listener
+being removed. This will not impact the order in which listeners are called,
+but it means that any copies of the listener array as returned by
+the emitter.listeners()
method will need to be recreated.
When a single function has been added as a handler multiple times for a single
+event (as in the example below), removeListener()
will remove the most
+recently added instance. In the example the once('ping')
listener is removed:
import { EventEmitter } from 'node:events';
const ee = new EventEmitter();
function pong() {
console.log('pong');
}
ee.on('ping', pong);
ee.once('ping', pong);
ee.removeListener('ping', pong);
ee.emit('ping');
ee.emit('ping');
+
+
+Returns a reference to the EventEmitter
, so that calls can be chained.
Rest
...args: any[]By default EventEmitter
s will print a warning if more than 10
listeners are
+added for a particular event. This is a useful default that helps finding
+memory leaks. The emitter.setMaxListeners()
method allows the limit to be
+modified for this specific EventEmitter
instance. The value can be set to Infinity
(or 0
) to indicate an unlimited number of listeners.
Returns a reference to the EventEmitter
, so that calls can be chained.
IDeck
-Represents the structure of a deck in a poker game.
LoggerConfig
Provides configuration options for the Logger
class, defining paths, output preferences, and general setup.
The LoggerConfig
interface standardizes the configuration settings for the logger, ensuring a flexible setup.
+This interface allows users to specify where logs should be stored (logDirPath
) and whether logging should also
+appear in the console (enableConsoleLogging
), thus supporting various logging needs in both development and
+production environments.
The LoggerConfig
interface can be used when initializing a logger to define the configuration that aligns with
+project-specific requirements.
LoggerInterface
Defines the structure for logging functionality, ensuring a consistent format for message logging +across different log levels and supporting optional data context.
+The LoggerInterface
interface establishes the required method for logging in various components
+within the application. It standardizes how log messages should be formatted and includes support
+for different levels of logging (info, warn, error).
log(level: LogLevel, message: string, data?: Record<string, any>): Promise<void>
:
+Logs a message with the specified level and optional additional data.The LoggerInterface
is implemented by the Logger
class to standardize how logging is handled.
+It can be used in classes and utilities where consistent logging behavior is necessary.
Logs a message with the specified level and optional additional data context. This method +is asynchronous to allow for file I/O or remote logging without blocking the application.
+Standardizes the logging of messages, allowing for log levels and structured data. +Provides flexibility in logging with additional context, such as an error stack or +metadata related to the log message.
+level: LogLevel
- The severity level of the log message (e.g., "info", "warn", "error").message: string
- The main message to be logged.data?: Record<string, any>
- Optional additional data that provides context for the log message.level
should be a valid log level defined in LogLevel
.message
should clearly describe the event or action.Promise<void>
- Returns a promise that resolves once the log has been processed.Use this method to log important events, errors, or debug information with optional +data for added context.
+The severity level of the log message.
+The main message to log.
+Optional
data: Record<string, any>Additional context data for the log (optional).
+PokerGameConfig
+Represents a Poker Game Config.
PokerGameInterface
+Represents the current PokerGame being played at the PokerTable.
+Manages the deck, community cards, and game phases, such as pre-flop, flop, turn, and river.
Optional
[captureRest
...args: AnyRestAlias for emitter.on(eventName, listener)
.
Rest
...args: any[]Synchronously calls each of the listeners registered for the event named eventName
, in the order they were registered, passing the supplied arguments
+to each.
Returns true
if the event had listeners, false
otherwise.
import { EventEmitter } from 'node:events';
const myEmitter = new EventEmitter();
// First listener
myEmitter.on('event', function firstListener() {
console.log('Helloooo! first listener');
});
// Second listener
myEmitter.on('event', function secondListener(arg1, arg2) {
console.log(`event with parameters ${arg1}, ${arg2} in second listener`);
});
// Third listener
myEmitter.on('event', function thirdListener(...args) {
const parameters = args.join(', ');
console.log(`event with parameters ${parameters} in third listener`);
});
console.log(myEmitter.listeners('event'));
myEmitter.emit('event', 1, 2, 3, 4, 5);
// Prints:
// [
// [Function: firstListener],
// [Function: secondListener],
// [Function: thirdListener]
// ]
// Helloooo! first listener
// event with parameters 1, 2 in second listener
// event with parameters 1, 2, 3, 4, 5 in third listener
+
+
+Rest
...args: AnyRestReturns an array listing the events for which the emitter has registered
+listeners. The values in the array are strings or Symbol
s.
import { EventEmitter } from 'node:events';
const myEE = new EventEmitter();
myEE.on('foo', () => {});
myEE.on('bar', () => {});
const sym = Symbol('symbol');
myEE.on(sym, () => {});
console.log(myEE.eventNames());
// Prints: [ 'foo', 'bar', Symbol(symbol) ]
+
+
+Returns the number of listeners listening for the event named eventName
.
+If listener
is provided, it will return how many times the listener is found
+in the list of the listeners of the event.
The name of the event being listened for
+Optional
listener: FunctionThe event handler function
+Returns a copy of the array of listeners for the event named eventName
.
server.on('connection', (stream) => {
console.log('someone connected!');
});
console.log(util.inspect(server.listeners('connection')));
// Prints: [ [Function] ]
+
+
+Alias for emitter.removeListener()
.
Rest
...args: any[]Adds the listener
function to the end of the listeners array for the event
+named eventName
. No checks are made to see if the listener
has already
+been added. Multiple calls passing the same combination of eventName
and
+listener
will result in the listener
being added, and called, multiple times.
server.on('connection', (stream) => {
console.log('someone connected!');
});
+
+
+Returns a reference to the EventEmitter
, so that calls can be chained.
By default, event listeners are invoked in the order they are added. The emitter.prependListener()
method can be used as an alternative to add the
+event listener to the beginning of the listeners array.
import { EventEmitter } from 'node:events';
const myEE = new EventEmitter();
myEE.on('foo', () => console.log('a'));
myEE.prependListener('foo', () => console.log('b'));
myEE.emit('foo');
// Prints:
// b
// a
+
+
+The name of the event.
+The callback function
+Rest
...args: any[]Adds a one-time listener
function for the event named eventName
. The
+next time eventName
is triggered, this listener is removed and then invoked.
server.once('connection', (stream) => {
console.log('Ah, we have our first user!');
});
+
+
+Returns a reference to the EventEmitter
, so that calls can be chained.
By default, event listeners are invoked in the order they are added. The emitter.prependOnceListener()
method can be used as an alternative to add the
+event listener to the beginning of the listeners array.
import { EventEmitter } from 'node:events';
const myEE = new EventEmitter();
myEE.once('foo', () => console.log('a'));
myEE.prependOnceListener('foo', () => console.log('b'));
myEE.emit('foo');
// Prints:
// b
// a
+
+
+The name of the event.
+The callback function
+Rest
...args: any[]Adds the listener
function to the beginning of the listeners array for the
+event named eventName
. No checks are made to see if the listener
has
+already been added. Multiple calls passing the same combination of eventName
+and listener
will result in the listener
being added, and called, multiple times.
server.prependListener('connection', (stream) => {
console.log('someone connected!');
});
+
+
+Returns a reference to the EventEmitter
, so that calls can be chained.
The name of the event.
+The callback function
+Rest
...args: any[]Adds a one-timelistener
function for the event named eventName
to the beginning of the listeners array. The next time eventName
is triggered, this
+listener is removed, and then invoked.
server.prependOnceListener('connection', (stream) => {
console.log('Ah, we have our first user!');
});
+
+
+Returns a reference to the EventEmitter
, so that calls can be chained.
The name of the event.
+The callback function
+Rest
...args: any[]Returns a copy of the array of listeners for the event named eventName
,
+including any wrappers (such as those created by .once()
).
import { EventEmitter } from 'node:events';
const emitter = new EventEmitter();
emitter.once('log', () => console.log('log once'));
// Returns a new Array with a function `onceWrapper` which has a property
// `listener` which contains the original listener bound above
const listeners = emitter.rawListeners('log');
const logFnWrapper = listeners[0];
// Logs "log once" to the console and does not unbind the `once` event
logFnWrapper.listener();
// Logs "log once" to the console and removes the listener
logFnWrapper();
emitter.on('log', () => console.log('log persistently'));
// Will return a new Array with a single function bound by `.on()` above
const newListeners = emitter.rawListeners('log');
// Logs "log persistently" twice
newListeners[0]();
emitter.emit('log');
+
+
+Removes all listeners, or those of the specified eventName
.
It is bad practice to remove listeners added elsewhere in the code,
+particularly when the EventEmitter
instance was created by some other
+component or module (e.g. sockets or file streams).
Returns a reference to the EventEmitter
, so that calls can be chained.
Optional
eventName: string | symbolRemoves the specified listener
from the listener array for the event named eventName
.
const callback = (stream) => {
console.log('someone connected!');
};
server.on('connection', callback);
// ...
server.removeListener('connection', callback);
+
+
+removeListener()
will remove, at most, one instance of a listener from the
+listener array. If any single listener has been added multiple times to the
+listener array for the specified eventName
, then removeListener()
must be
+called multiple times to remove each instance.
Once an event is emitted, all listeners attached to it at the
+time of emitting are called in order. This implies that any removeListener()
or removeAllListeners()
calls after emitting and before the last listener finishes execution
+will not remove them fromemit()
in progress. Subsequent events behave as expected.
import { EventEmitter } from 'node:events';
class MyEmitter extends EventEmitter {}
const myEmitter = new MyEmitter();
const callbackA = () => {
console.log('A');
myEmitter.removeListener('event', callbackB);
};
const callbackB = () => {
console.log('B');
};
myEmitter.on('event', callbackA);
myEmitter.on('event', callbackB);
// callbackA removes listener callbackB but it will still be called.
// Internal listener array at time of emit [callbackA, callbackB]
myEmitter.emit('event');
// Prints:
// A
// B
// callbackB is now removed.
// Internal listener array [callbackA]
myEmitter.emit('event');
// Prints:
// A
+
+
+Because listeners are managed using an internal array, calling this will
+change the position indices of any listener registered after the listener
+being removed. This will not impact the order in which listeners are called,
+but it means that any copies of the listener array as returned by
+the emitter.listeners()
method will need to be recreated.
When a single function has been added as a handler multiple times for a single
+event (as in the example below), removeListener()
will remove the most
+recently added instance. In the example the once('ping')
listener is removed:
import { EventEmitter } from 'node:events';
const ee = new EventEmitter();
function pong() {
console.log('pong');
}
ee.on('ping', pong);
ee.once('ping', pong);
ee.removeListener('ping', pong);
ee.emit('ping');
ee.emit('ping');
+
+
+Returns a reference to the EventEmitter
, so that calls can be chained.
Rest
...args: any[]By default EventEmitter
s will print a warning if more than 10
listeners are
+added for a particular event. This is a useful default that helps finding
+memory leaks. The emitter.setMaxListeners()
method allows the limit to be
+modified for this specific EventEmitter
instance. The value can be set to Infinity
(or 0
) to indicate an unlimited number of listeners.
Returns a reference to the EventEmitter
, so that calls can be chained.
PokerPhaseConfig
+Represents a Poker Phase Config.
PokerPhaseInterface
+Represents the current PokerPhase being played at the PokerTable.
+Manages the deck, community cards, and game phases, such as pre-flop, flop, turn, and river.
Optional
[captureRest
...args: AnyRestAlias for emitter.on(eventName, listener)
.
Rest
...args: any[]Synchronously calls each of the listeners registered for the event named eventName
, in the order they were registered, passing the supplied arguments
+to each.
Returns true
if the event had listeners, false
otherwise.
import { EventEmitter } from 'node:events';
const myEmitter = new EventEmitter();
// First listener
myEmitter.on('event', function firstListener() {
console.log('Helloooo! first listener');
});
// Second listener
myEmitter.on('event', function secondListener(arg1, arg2) {
console.log(`event with parameters ${arg1}, ${arg2} in second listener`);
});
// Third listener
myEmitter.on('event', function thirdListener(...args) {
const parameters = args.join(', ');
console.log(`event with parameters ${parameters} in third listener`);
});
console.log(myEmitter.listeners('event'));
myEmitter.emit('event', 1, 2, 3, 4, 5);
// Prints:
// [
// [Function: firstListener],
// [Function: secondListener],
// [Function: thirdListener]
// ]
// Helloooo! first listener
// event with parameters 1, 2 in second listener
// event with parameters 1, 2, 3, 4, 5 in third listener
+
+
+Rest
...args: AnyRestReturns an array listing the events for which the emitter has registered
+listeners. The values in the array are strings or Symbol
s.
import { EventEmitter } from 'node:events';
const myEE = new EventEmitter();
myEE.on('foo', () => {});
myEE.on('bar', () => {});
const sym = Symbol('symbol');
myEE.on(sym, () => {});
console.log(myEE.eventNames());
// Prints: [ 'foo', 'bar', Symbol(symbol) ]
+
+
+Returns the number of listeners listening for the event named eventName
.
+If listener
is provided, it will return how many times the listener is found
+in the list of the listeners of the event.
The name of the event being listened for
+Optional
listener: FunctionThe event handler function
+Returns a copy of the array of listeners for the event named eventName
.
server.on('connection', (stream) => {
console.log('someone connected!');
});
console.log(util.inspect(server.listeners('connection')));
// Prints: [ [Function] ]
+
+
+Alias for emitter.removeListener()
.
Rest
...args: any[]Adds the listener
function to the end of the listeners array for the event
+named eventName
. No checks are made to see if the listener
has already
+been added. Multiple calls passing the same combination of eventName
and
+listener
will result in the listener
being added, and called, multiple times.
server.on('connection', (stream) => {
console.log('someone connected!');
});
+
+
+Returns a reference to the EventEmitter
, so that calls can be chained.
By default, event listeners are invoked in the order they are added. The emitter.prependListener()
method can be used as an alternative to add the
+event listener to the beginning of the listeners array.
import { EventEmitter } from 'node:events';
const myEE = new EventEmitter();
myEE.on('foo', () => console.log('a'));
myEE.prependListener('foo', () => console.log('b'));
myEE.emit('foo');
// Prints:
// b
// a
+
+
+The name of the event.
+The callback function
+Rest
...args: any[]Adds a one-time listener
function for the event named eventName
. The
+next time eventName
is triggered, this listener is removed and then invoked.
server.once('connection', (stream) => {
console.log('Ah, we have our first user!');
});
+
+
+Returns a reference to the EventEmitter
, so that calls can be chained.
By default, event listeners are invoked in the order they are added. The emitter.prependOnceListener()
method can be used as an alternative to add the
+event listener to the beginning of the listeners array.
import { EventEmitter } from 'node:events';
const myEE = new EventEmitter();
myEE.once('foo', () => console.log('a'));
myEE.prependOnceListener('foo', () => console.log('b'));
myEE.emit('foo');
// Prints:
// b
// a
+
+
+The name of the event.
+The callback function
+Rest
...args: any[]Adds the listener
function to the beginning of the listeners array for the
+event named eventName
. No checks are made to see if the listener
has
+already been added. Multiple calls passing the same combination of eventName
+and listener
will result in the listener
being added, and called, multiple times.
server.prependListener('connection', (stream) => {
console.log('someone connected!');
});
+
+
+Returns a reference to the EventEmitter
, so that calls can be chained.
The name of the event.
+The callback function
+Rest
...args: any[]Adds a one-timelistener
function for the event named eventName
to the beginning of the listeners array. The next time eventName
is triggered, this
+listener is removed, and then invoked.
server.prependOnceListener('connection', (stream) => {
console.log('Ah, we have our first user!');
});
+
+
+Returns a reference to the EventEmitter
, so that calls can be chained.
The name of the event.
+The callback function
+Rest
...args: any[]Returns a copy of the array of listeners for the event named eventName
,
+including any wrappers (such as those created by .once()
).
import { EventEmitter } from 'node:events';
const emitter = new EventEmitter();
emitter.once('log', () => console.log('log once'));
// Returns a new Array with a function `onceWrapper` which has a property
// `listener` which contains the original listener bound above
const listeners = emitter.rawListeners('log');
const logFnWrapper = listeners[0];
// Logs "log once" to the console and does not unbind the `once` event
logFnWrapper.listener();
// Logs "log once" to the console and removes the listener
logFnWrapper();
emitter.on('log', () => console.log('log persistently'));
// Will return a new Array with a single function bound by `.on()` above
const newListeners = emitter.rawListeners('log');
// Logs "log persistently" twice
newListeners[0]();
emitter.emit('log');
+
+
+Removes all listeners, or those of the specified eventName
.
It is bad practice to remove listeners added elsewhere in the code,
+particularly when the EventEmitter
instance was created by some other
+component or module (e.g. sockets or file streams).
Returns a reference to the EventEmitter
, so that calls can be chained.
Optional
eventName: string | symbolRemoves the specified listener
from the listener array for the event named eventName
.
const callback = (stream) => {
console.log('someone connected!');
};
server.on('connection', callback);
// ...
server.removeListener('connection', callback);
+
+
+removeListener()
will remove, at most, one instance of a listener from the
+listener array. If any single listener has been added multiple times to the
+listener array for the specified eventName
, then removeListener()
must be
+called multiple times to remove each instance.
Once an event is emitted, all listeners attached to it at the
+time of emitting are called in order. This implies that any removeListener()
or removeAllListeners()
calls after emitting and before the last listener finishes execution
+will not remove them fromemit()
in progress. Subsequent events behave as expected.
import { EventEmitter } from 'node:events';
class MyEmitter extends EventEmitter {}
const myEmitter = new MyEmitter();
const callbackA = () => {
console.log('A');
myEmitter.removeListener('event', callbackB);
};
const callbackB = () => {
console.log('B');
};
myEmitter.on('event', callbackA);
myEmitter.on('event', callbackB);
// callbackA removes listener callbackB but it will still be called.
// Internal listener array at time of emit [callbackA, callbackB]
myEmitter.emit('event');
// Prints:
// A
// B
// callbackB is now removed.
// Internal listener array [callbackA]
myEmitter.emit('event');
// Prints:
// A
+
+
+Because listeners are managed using an internal array, calling this will
+change the position indices of any listener registered after the listener
+being removed. This will not impact the order in which listeners are called,
+but it means that any copies of the listener array as returned by
+the emitter.listeners()
method will need to be recreated.
When a single function has been added as a handler multiple times for a single
+event (as in the example below), removeListener()
will remove the most
+recently added instance. In the example the once('ping')
listener is removed:
import { EventEmitter } from 'node:events';
const ee = new EventEmitter();
function pong() {
console.log('pong');
}
ee.on('ping', pong);
ee.once('ping', pong);
ee.removeListener('ping', pong);
ee.emit('ping');
ee.emit('ping');
+
+
+Returns a reference to the EventEmitter
, so that calls can be chained.
Rest
...args: any[]By default EventEmitter
s will print a warning if more than 10
listeners are
+added for a particular event. This is a useful default that helps finding
+memory leaks. The emitter.setMaxListeners()
method allows the limit to be
+modified for this specific EventEmitter
instance. The value can be set to Infinity
(or 0
) to indicate an unlimited number of listeners.
Returns a reference to the EventEmitter
, so that calls can be chained.
PokerPlayerInterface
+Represents a player seated at the PokerTable.
+The player can place bets, fold, and manage their chip stack during the game.
Optional
[captureRest
...args: AnyRestAlias for emitter.on(eventName, listener)
.
Rest
...args: any[]Synchronously calls each of the listeners registered for the event named eventName
, in the order they were registered, passing the supplied arguments
+to each.
Returns true
if the event had listeners, false
otherwise.
import { EventEmitter } from 'node:events';
const myEmitter = new EventEmitter();
// First listener
myEmitter.on('event', function firstListener() {
console.log('Helloooo! first listener');
});
// Second listener
myEmitter.on('event', function secondListener(arg1, arg2) {
console.log(`event with parameters ${arg1}, ${arg2} in second listener`);
});
// Third listener
myEmitter.on('event', function thirdListener(...args) {
const parameters = args.join(', ');
console.log(`event with parameters ${parameters} in third listener`);
});
console.log(myEmitter.listeners('event'));
myEmitter.emit('event', 1, 2, 3, 4, 5);
// Prints:
// [
// [Function: firstListener],
// [Function: secondListener],
// [Function: thirdListener]
// ]
// Helloooo! first listener
// event with parameters 1, 2 in second listener
// event with parameters 1, 2, 3, 4, 5 in third listener
+
+
+Rest
...args: AnyRestReturns an array listing the events for which the emitter has registered
+listeners. The values in the array are strings or Symbol
s.
import { EventEmitter } from 'node:events';
const myEE = new EventEmitter();
myEE.on('foo', () => {});
myEE.on('bar', () => {});
const sym = Symbol('symbol');
myEE.on(sym, () => {});
console.log(myEE.eventNames());
// Prints: [ 'foo', 'bar', Symbol(symbol) ]
+
+
+Returns the number of listeners listening for the event named eventName
.
+If listener
is provided, it will return how many times the listener is found
+in the list of the listeners of the event.
The name of the event being listened for
+Optional
listener: FunctionThe event handler function
+Returns a copy of the array of listeners for the event named eventName
.
server.on('connection', (stream) => {
console.log('someone connected!');
});
console.log(util.inspect(server.listeners('connection')));
// Prints: [ [Function] ]
+
+
+Alias for emitter.removeListener()
.
Rest
...args: any[]Adds the listener
function to the end of the listeners array for the event
+named eventName
. No checks are made to see if the listener
has already
+been added. Multiple calls passing the same combination of eventName
and
+listener
will result in the listener
being added, and called, multiple times.
server.on('connection', (stream) => {
console.log('someone connected!');
});
+
+
+Returns a reference to the EventEmitter
, so that calls can be chained.
By default, event listeners are invoked in the order they are added. The emitter.prependListener()
method can be used as an alternative to add the
+event listener to the beginning of the listeners array.
import { EventEmitter } from 'node:events';
const myEE = new EventEmitter();
myEE.on('foo', () => console.log('a'));
myEE.prependListener('foo', () => console.log('b'));
myEE.emit('foo');
// Prints:
// b
// a
+
+
+The name of the event.
+The callback function
+Rest
...args: any[]Adds a one-time listener
function for the event named eventName
. The
+next time eventName
is triggered, this listener is removed and then invoked.
server.once('connection', (stream) => {
console.log('Ah, we have our first user!');
});
+
+
+Returns a reference to the EventEmitter
, so that calls can be chained.
By default, event listeners are invoked in the order they are added. The emitter.prependOnceListener()
method can be used as an alternative to add the
+event listener to the beginning of the listeners array.
import { EventEmitter } from 'node:events';
const myEE = new EventEmitter();
myEE.once('foo', () => console.log('a'));
myEE.prependOnceListener('foo', () => console.log('b'));
myEE.emit('foo');
// Prints:
// b
// a
+
+
+The name of the event.
+The callback function
+Rest
...args: any[]Adds the listener
function to the beginning of the listeners array for the
+event named eventName
. No checks are made to see if the listener
has
+already been added. Multiple calls passing the same combination of eventName
+and listener
will result in the listener
being added, and called, multiple times.
server.prependListener('connection', (stream) => {
console.log('someone connected!');
});
+
+
+Returns a reference to the EventEmitter
, so that calls can be chained.
The name of the event.
+The callback function
+Rest
...args: any[]Adds a one-timelistener
function for the event named eventName
to the beginning of the listeners array. The next time eventName
is triggered, this
+listener is removed, and then invoked.
server.prependOnceListener('connection', (stream) => {
console.log('Ah, we have our first user!');
});
+
+
+Returns a reference to the EventEmitter
, so that calls can be chained.
The name of the event.
+The callback function
+Rest
...args: any[]Returns a copy of the array of listeners for the event named eventName
,
+including any wrappers (such as those created by .once()
).
import { EventEmitter } from 'node:events';
const emitter = new EventEmitter();
emitter.once('log', () => console.log('log once'));
// Returns a new Array with a function `onceWrapper` which has a property
// `listener` which contains the original listener bound above
const listeners = emitter.rawListeners('log');
const logFnWrapper = listeners[0];
// Logs "log once" to the console and does not unbind the `once` event
logFnWrapper.listener();
// Logs "log once" to the console and removes the listener
logFnWrapper();
emitter.on('log', () => console.log('log persistently'));
// Will return a new Array with a single function bound by `.on()` above
const newListeners = emitter.rawListeners('log');
// Logs "log persistently" twice
newListeners[0]();
emitter.emit('log');
+
+
+Removes all listeners, or those of the specified eventName
.
It is bad practice to remove listeners added elsewhere in the code,
+particularly when the EventEmitter
instance was created by some other
+component or module (e.g. sockets or file streams).
Returns a reference to the EventEmitter
, so that calls can be chained.
Optional
eventName: string | symbolRemoves the specified listener
from the listener array for the event named eventName
.
const callback = (stream) => {
console.log('someone connected!');
};
server.on('connection', callback);
// ...
server.removeListener('connection', callback);
+
+
+removeListener()
will remove, at most, one instance of a listener from the
+listener array. If any single listener has been added multiple times to the
+listener array for the specified eventName
, then removeListener()
must be
+called multiple times to remove each instance.
Once an event is emitted, all listeners attached to it at the
+time of emitting are called in order. This implies that any removeListener()
or removeAllListeners()
calls after emitting and before the last listener finishes execution
+will not remove them fromemit()
in progress. Subsequent events behave as expected.
import { EventEmitter } from 'node:events';
class MyEmitter extends EventEmitter {}
const myEmitter = new MyEmitter();
const callbackA = () => {
console.log('A');
myEmitter.removeListener('event', callbackB);
};
const callbackB = () => {
console.log('B');
};
myEmitter.on('event', callbackA);
myEmitter.on('event', callbackB);
// callbackA removes listener callbackB but it will still be called.
// Internal listener array at time of emit [callbackA, callbackB]
myEmitter.emit('event');
// Prints:
// A
// B
// callbackB is now removed.
// Internal listener array [callbackA]
myEmitter.emit('event');
// Prints:
// A
+
+
+Because listeners are managed using an internal array, calling this will
+change the position indices of any listener registered after the listener
+being removed. This will not impact the order in which listeners are called,
+but it means that any copies of the listener array as returned by
+the emitter.listeners()
method will need to be recreated.
When a single function has been added as a handler multiple times for a single
+event (as in the example below), removeListener()
will remove the most
+recently added instance. In the example the once('ping')
listener is removed:
import { EventEmitter } from 'node:events';
const ee = new EventEmitter();
function pong() {
console.log('pong');
}
ee.on('ping', pong);
ee.once('ping', pong);
ee.removeListener('ping', pong);
ee.emit('ping');
ee.emit('ping');
+
+
+Returns a reference to the EventEmitter
, so that calls can be chained.
Rest
...args: any[]By default EventEmitter
s will print a warning if more than 10
listeners are
+added for a particular event. This is a useful default that helps finding
+memory leaks. The emitter.setMaxListeners()
method allows the limit to be
+modified for this specific EventEmitter
instance. The value can be set to Infinity
(or 0
) to indicate an unlimited number of listeners.
Returns a reference to the EventEmitter
, so that calls can be chained.
PokerRoomConfig
Represents the configuration settings necessary to create a PokerRoom
within the Casino system.
+This interface defines core properties such as a unique identifier (id
), room name (name
),
+and an array of table configurations (tableConfigs
) that standardize room setup and ensure consistent
+properties across all PokerRoom
instances.
The PokerRoomConfig
interface serves as a blueprint for initializing PokerRoom
instances.
+By defining required properties upfront, this configuration helps streamline room creation,
+reduce errors, and maintain uniformity across room instances within the Casino system.
The interface includes:
+id
and name
properties for unique identification and naming of the room.tableConfigs
, that holds one or more configurations detailing each table's settings within the room.Primarily used as an input for the PokerRoom
constructor, PokerRoomConfig
allows developers
+to define each room’s essential properties during instantiation. This structure helps prevent
+setup errors and ensures consistency among multiple rooms in the Casino.
tableConfigs
: Must be a valid array containing one or more PokerTableConfig
objects.id
and name
(optional): Enhance room uniqueness and readability, if provided.const roomConfig: PokerRoomConfig = {
id: "room42",
name: "High Stakes",
tableConfigs: [
{ tableSize: 6, smallBlind: 50, bigBlind: 100 },
{ tableSize: 8, smallBlind: 100, bigBlind: 200 }
]
};
const pokerRoom = new PokerRoom(roomConfig); // Initializes a new PokerRoom with the specified configuration
+
+
+Optional
idOptional
nameOptional
tableconst roomConfig: PokerRoomConfig = {
id: "room3",
name: "Beginner's Lounge",
tableConfigs: [
{ tableSize: 4, smallBlind: 5, bigBlind: 10 },
{ tableSize: 6, smallBlind: 10, bigBlind: 20 }
]
};
console.log(roomConfig.tableConfigs);
// Output: [{ tableSize: 4, smallBlind: 5, bigBlind: 10 }, { tableSize: 6, smallBlind: 10, bigBlind: 20 }]
+
+
+PokerRoomInterface
Defines the responsibilities and structure for managing a PokerRoom
within the Casino system. This interface is
+essential for implementing operations such as room setup, player queue management, and table configuration, thereby
+organizing and facilitating smooth poker game management.
The PokerRoomInterface
serves as a standardized blueprint for any PokerRoom
class, detailing essential methods
+for room configuration, player management, and table access. By following this structure, the system ensures that each
+poker room is identifiable, manageable, and consistent in functionality.
This interface extends NodeJS.EventEmitter
to allow event-driven management of room actions like table updates,
+player entry, or exit events, enhancing flexibility in asynchronous operations across the Casino system.
The PokerRoomInterface
includes the following methods:
The PokerRoomInterface
includes the following events:
This interface is designed to standardize the management of PokerRoom
instances, offering a complete structure for
+both client-facing interactions (like displaying room details) and internal operations (like seating players or adjusting
+tables).
Optional
[captureRest
...args: AnyRestAlias for emitter.on(eventName, listener)
.
Rest
...args: any[]Synchronously calls each of the listeners registered for the event named eventName
, in the order they were registered, passing the supplied arguments
+to each.
Returns true
if the event had listeners, false
otherwise.
import { EventEmitter } from 'node:events';
const myEmitter = new EventEmitter();
// First listener
myEmitter.on('event', function firstListener() {
console.log('Helloooo! first listener');
});
// Second listener
myEmitter.on('event', function secondListener(arg1, arg2) {
console.log(`event with parameters ${arg1}, ${arg2} in second listener`);
});
// Third listener
myEmitter.on('event', function thirdListener(...args) {
const parameters = args.join(', ');
console.log(`event with parameters ${parameters} in third listener`);
});
console.log(myEmitter.listeners('event'));
myEmitter.emit('event', 1, 2, 3, 4, 5);
// Prints:
// [
// [Function: firstListener],
// [Function: secondListener],
// [Function: thirdListener]
// ]
// Helloooo! first listener
// event with parameters 1, 2 in second listener
// event with parameters 1, 2, 3, 4, 5 in third listener
+
+
+Rest
...args: AnyRestReturns an array listing the events for which the emitter has registered
+listeners. The values in the array are strings or Symbol
s.
import { EventEmitter } from 'node:events';
const myEE = new EventEmitter();
myEE.on('foo', () => {});
myEE.on('bar', () => {});
const sym = Symbol('symbol');
myEE.on(sym, () => {});
console.log(myEE.eventNames());
// Prints: [ 'foo', 'bar', Symbol(symbol) ]
+
+
+Retrieves the unique identifier of the PokerRoom
.
N/A
- This method is defined within the PokerRoomInterface
without implementing external methods.
N/A
- This method does not override any superclass or parent methods.
The getId
method enables access to the unique id
of a PokerRoom
, which is essential for identifying
+and referencing specific rooms within the system.
N/A
- No events are emitted by this method.
N/A
- This method does not require any parameters.
N/A
- This method simply returns the id
as set by the setId
method.
id
of the PokerRoom
as a string.Use this method to retrieve the identifier of a PokerRoom
. This is particularly useful for managing,
+searching, or displaying room information.
PokerRoom
.Retrieves the current name of the PokerRoom
.
N/A
- This method is defined within PokerRoomInterface
and is implemented by any class adhering to this interface.
N/A
- This method does not override any superclass or parent methods.
The getName
method enables access to the current name of a PokerRoom
, which can be essential for
+identification, logging, and displaying room information to users.
N/A
- No events are emitted by this method.
N/A
- This method does not require any parameters.
N/A
- This method simply returns the current name as set by setName
.
PokerRoom
as a string.Use this method to fetch the current name of a PokerRoom
. This can be particularly helpful for displaying
+or verifying the room name during operations.
PokerRoom
.Retrieves the associated PokerTable
instance within the PokerRoom
.
N/A
- This method does not implement external interfaces.
N/A
- This method does not override any superclass or parent methods.
The getTable
method provides access to the PokerTable
instance that is actively managed by the PokerRoom
.
+This can be used to view table configuration, status, and player seating arrangements.
N/A
- This method does not emit any events.
N/A
- No parameters are required for this method.
N/A
- This method does not modify the table, only retrieves it.
PokerTableInterface
instance currently set for the room.Use this method to access the poker table associated with a specific room. This allows for table-specific +operations and inquiries.
+PokerTable
instance associated with this room.Validates if a specified index is within the valid bounds of the Casino’s room list.
+N/A
N/A
Prevents out-of-bounds errors by confirming that an index is within the acceptable range for the Casino’s +room list, ensuring that subsequent calls to access rooms by index have a valid target.
+N/A
index
: A zero-based integer specifying the position of a room within the Casino's managed room list.index
must be a non-negative integer within the bounds of the __rooms
array.true
if the index is within bounds.Error
if the index is out of bounds.Call this method before performing operations involving indexed access to rooms, ensuring the index +falls within valid boundaries.
+The zero-based index to validate within the room list.
+true
if the index is within bounds.Returns the number of listeners listening for the event named eventName
.
+If listener
is provided, it will return how many times the listener is found
+in the list of the listeners of the event.
The name of the event being listened for
+Optional
listener: FunctionThe event handler function
+Returns a copy of the array of listeners for the event named eventName
.
server.on('connection', (stream) => {
console.log('someone connected!');
});
console.log(util.inspect(server.listeners('connection')));
// Prints: [ [Function] ]
+
+
+Alias for emitter.removeListener()
.
Rest
...args: any[]Adds the listener
function to the end of the listeners array for the event
+named eventName
. No checks are made to see if the listener
has already
+been added. Multiple calls passing the same combination of eventName
and
+listener
will result in the listener
being added, and called, multiple times.
server.on('connection', (stream) => {
console.log('someone connected!');
});
+
+
+Returns a reference to the EventEmitter
, so that calls can be chained.
By default, event listeners are invoked in the order they are added. The emitter.prependListener()
method can be used as an alternative to add the
+event listener to the beginning of the listeners array.
import { EventEmitter } from 'node:events';
const myEE = new EventEmitter();
myEE.on('foo', () => console.log('a'));
myEE.prependListener('foo', () => console.log('b'));
myEE.emit('foo');
// Prints:
// b
// a
+
+
+The name of the event.
+The callback function
+Rest
...args: any[]Adds a one-time listener
function for the event named eventName
. The
+next time eventName
is triggered, this listener is removed and then invoked.
server.once('connection', (stream) => {
console.log('Ah, we have our first user!');
});
+
+
+Returns a reference to the EventEmitter
, so that calls can be chained.
By default, event listeners are invoked in the order they are added. The emitter.prependOnceListener()
method can be used as an alternative to add the
+event listener to the beginning of the listeners array.
import { EventEmitter } from 'node:events';
const myEE = new EventEmitter();
myEE.once('foo', () => console.log('a'));
myEE.prependOnceListener('foo', () => console.log('b'));
myEE.emit('foo');
// Prints:
// b
// a
+
+
+The name of the event.
+The callback function
+Rest
...args: any[]Adds the listener
function to the beginning of the listeners array for the
+event named eventName
. No checks are made to see if the listener
has
+already been added. Multiple calls passing the same combination of eventName
+and listener
will result in the listener
being added, and called, multiple times.
server.prependListener('connection', (stream) => {
console.log('someone connected!');
});
+
+
+Returns a reference to the EventEmitter
, so that calls can be chained.
The name of the event.
+The callback function
+Rest
...args: any[]Adds a one-timelistener
function for the event named eventName
to the beginning of the listeners array. The next time eventName
is triggered, this
+listener is removed, and then invoked.
server.prependOnceListener('connection', (stream) => {
console.log('Ah, we have our first user!');
});
+
+
+Returns a reference to the EventEmitter
, so that calls can be chained.
The name of the event.
+The callback function
+Rest
...args: any[]Returns a copy of the array of listeners for the event named eventName
,
+including any wrappers (such as those created by .once()
).
import { EventEmitter } from 'node:events';
const emitter = new EventEmitter();
emitter.once('log', () => console.log('log once'));
// Returns a new Array with a function `onceWrapper` which has a property
// `listener` which contains the original listener bound above
const listeners = emitter.rawListeners('log');
const logFnWrapper = listeners[0];
// Logs "log once" to the console and does not unbind the `once` event
logFnWrapper.listener();
// Logs "log once" to the console and removes the listener
logFnWrapper();
emitter.on('log', () => console.log('log persistently'));
// Will return a new Array with a single function bound by `.on()` above
const newListeners = emitter.rawListeners('log');
// Logs "log persistently" twice
newListeners[0]();
emitter.emit('log');
+
+
+Removes all listeners, or those of the specified eventName
.
It is bad practice to remove listeners added elsewhere in the code,
+particularly when the EventEmitter
instance was created by some other
+component or module (e.g. sockets or file streams).
Returns a reference to the EventEmitter
, so that calls can be chained.
Optional
eventName: string | symbolRemoves the specified listener
from the listener array for the event named eventName
.
const callback = (stream) => {
console.log('someone connected!');
};
server.on('connection', callback);
// ...
server.removeListener('connection', callback);
+
+
+removeListener()
will remove, at most, one instance of a listener from the
+listener array. If any single listener has been added multiple times to the
+listener array for the specified eventName
, then removeListener()
must be
+called multiple times to remove each instance.
Once an event is emitted, all listeners attached to it at the
+time of emitting are called in order. This implies that any removeListener()
or removeAllListeners()
calls after emitting and before the last listener finishes execution
+will not remove them fromemit()
in progress. Subsequent events behave as expected.
import { EventEmitter } from 'node:events';
class MyEmitter extends EventEmitter {}
const myEmitter = new MyEmitter();
const callbackA = () => {
console.log('A');
myEmitter.removeListener('event', callbackB);
};
const callbackB = () => {
console.log('B');
};
myEmitter.on('event', callbackA);
myEmitter.on('event', callbackB);
// callbackA removes listener callbackB but it will still be called.
// Internal listener array at time of emit [callbackA, callbackB]
myEmitter.emit('event');
// Prints:
// A
// B
// callbackB is now removed.
// Internal listener array [callbackA]
myEmitter.emit('event');
// Prints:
// A
+
+
+Because listeners are managed using an internal array, calling this will
+change the position indices of any listener registered after the listener
+being removed. This will not impact the order in which listeners are called,
+but it means that any copies of the listener array as returned by
+the emitter.listeners()
method will need to be recreated.
When a single function has been added as a handler multiple times for a single
+event (as in the example below), removeListener()
will remove the most
+recently added instance. In the example the once('ping')
listener is removed:
import { EventEmitter } from 'node:events';
const ee = new EventEmitter();
function pong() {
console.log('pong');
}
ee.on('ping', pong);
ee.once('ping', pong);
ee.removeListener('ping', pong);
ee.emit('ping');
ee.emit('ping');
+
+
+Returns a reference to the EventEmitter
, so that calls can be chained.
Rest
...args: any[]By default EventEmitter
s will print a warning if more than 10
listeners are
+added for a particular event. This is a useful default that helps finding
+memory leaks. The emitter.setMaxListeners()
method allows the limit to be
+modified for this specific EventEmitter
instance. The value can be set to Infinity
(or 0
) to indicate an unlimited number of listeners.
Returns a reference to the EventEmitter
, so that calls can be chained.
Sets the name of the PokerRoom
, allowing the name to be updated or customized.
N/A
- This method is part of the PokerRoomInterface
and does not implement any external methods.
N/A
- This method does not override any superclass or parent methods.
The setName
method is used to assign a specific name to a PokerRoom
, which helps distinguish it within the system.
+This is essential for systems where rooms need to be identifiable and manageable through a unique name.
N/A
- No events are emitted by this method.
name
: A string representing the new name for the room. It must be a valid, non-empty string to ensure
+the room has a clear, identifiable label.name
parameter should be a non-empty string to provide meaningful identification.name
that was set for the PokerRoom
.Use this method to set or update the name of a room in a system where unique or identifiable room names +are necessary for reference.
+The new name for the PokerRoom
.
Sets the configuration for multiple tables within the PokerRoom
. Each table configuration specifies
+key attributes like table size, small blind, and big blind values, supporting multi-table configurations
+within a single room.
N/A
- This method is part of the PokerRoomInterface
and does not implement any external methods.
N/A
- This method does not override any superclass or parent methods.
The setTables
method is crucial for defining or updating the configuration of multiple tables in a room.
+Properly configured tables are essential for ensuring smooth gameplay and an organized player experience.
tables
: An array of PokerTableInterface
objects, each containing configuration details for a table.tables
must be a non-empty array of PokerTableInterface
instances, each configured with necessary game parameters.PokerTableInterface
instances after successfully setting them within the room.Call this method to configure or update multiple tables in a poker room, ensuring the settings align with +room requirements and player needs.
+The list of table configurations for the poker room.
+const pokerRoom = new PokerRoom({ name: "Room3", tableSize: 8 });
const tableConfigs = [
new PokerTable({ tableSize: 8, smallBlind: 10, bigBlind: 20 }),
new PokerTable({ tableSize: 10, smallBlind: 20, bigBlind: 40 })
];
pokerRoom.setTables(tableConfigs); // Sets multiple table configurations in the room
console.log(pokerRoom.getTables()); // Logs the table configurations
+
+
+Retrieves the total number of PokerRoom
instances currently managed by the Casino.
N/A
N/A
This method provides insight into the number of poker rooms that the Casino manages, supporting +validation for index-bound operations or general information on Casino state.
+N/A
N/A
N/A
Use this method to retrieve the total count of active poker rooms, which is helpful when iterating over +rooms or confirming index-bound conditions.
+PokerSeatConfig
+Represents a PokerTable Config.
PokerSeatInterface
+Represents a PokerTable within a PokerRoom.
+The PokerTable manages player seats, tracks the dealer, small blind, and big blind positions,
+and handles the start and stop of the PokerGame.
Optional
[captureRest
...args: AnyRestAlias for emitter.on(eventName, listener)
.
Rest
...args: any[]Synchronously calls each of the listeners registered for the event named eventName
, in the order they were registered, passing the supplied arguments
+to each.
Returns true
if the event had listeners, false
otherwise.
import { EventEmitter } from 'node:events';
const myEmitter = new EventEmitter();
// First listener
myEmitter.on('event', function firstListener() {
console.log('Helloooo! first listener');
});
// Second listener
myEmitter.on('event', function secondListener(arg1, arg2) {
console.log(`event with parameters ${arg1}, ${arg2} in second listener`);
});
// Third listener
myEmitter.on('event', function thirdListener(...args) {
const parameters = args.join(', ');
console.log(`event with parameters ${parameters} in third listener`);
});
console.log(myEmitter.listeners('event'));
myEmitter.emit('event', 1, 2, 3, 4, 5);
// Prints:
// [
// [Function: firstListener],
// [Function: secondListener],
// [Function: thirdListener]
// ]
// Helloooo! first listener
// event with parameters 1, 2 in second listener
// event with parameters 1, 2, 3, 4, 5 in third listener
+
+
+Rest
...args: AnyRestReturns an array listing the events for which the emitter has registered
+listeners. The values in the array are strings or Symbol
s.
import { EventEmitter } from 'node:events';
const myEE = new EventEmitter();
myEE.on('foo', () => {});
myEE.on('bar', () => {});
const sym = Symbol('symbol');
myEE.on(sym, () => {});
console.log(myEE.eventNames());
// Prints: [ 'foo', 'bar', Symbol(symbol) ]
+
+
+getPlayer
Returns the poker table's id
.
The poker table's id
.
Returns the number of listeners listening for the event named eventName
.
+If listener
is provided, it will return how many times the listener is found
+in the list of the listeners of the event.
The name of the event being listened for
+Optional
listener: FunctionThe event handler function
+Returns a copy of the array of listeners for the event named eventName
.
server.on('connection', (stream) => {
console.log('someone connected!');
});
console.log(util.inspect(server.listeners('connection')));
// Prints: [ [Function] ]
+
+
+Alias for emitter.removeListener()
.
Rest
...args: any[]Adds the listener
function to the end of the listeners array for the event
+named eventName
. No checks are made to see if the listener
has already
+been added. Multiple calls passing the same combination of eventName
and
+listener
will result in the listener
being added, and called, multiple times.
server.on('connection', (stream) => {
console.log('someone connected!');
});
+
+
+Returns a reference to the EventEmitter
, so that calls can be chained.
By default, event listeners are invoked in the order they are added. The emitter.prependListener()
method can be used as an alternative to add the
+event listener to the beginning of the listeners array.
import { EventEmitter } from 'node:events';
const myEE = new EventEmitter();
myEE.on('foo', () => console.log('a'));
myEE.prependListener('foo', () => console.log('b'));
myEE.emit('foo');
// Prints:
// b
// a
+
+
+The name of the event.
+The callback function
+Rest
...args: any[]Adds a one-time listener
function for the event named eventName
. The
+next time eventName
is triggered, this listener is removed and then invoked.
server.once('connection', (stream) => {
console.log('Ah, we have our first user!');
});
+
+
+Returns a reference to the EventEmitter
, so that calls can be chained.
By default, event listeners are invoked in the order they are added. The emitter.prependOnceListener()
method can be used as an alternative to add the
+event listener to the beginning of the listeners array.
import { EventEmitter } from 'node:events';
const myEE = new EventEmitter();
myEE.once('foo', () => console.log('a'));
myEE.prependOnceListener('foo', () => console.log('b'));
myEE.emit('foo');
// Prints:
// b
// a
+
+
+The name of the event.
+The callback function
+Rest
...args: any[]Adds the listener
function to the beginning of the listeners array for the
+event named eventName
. No checks are made to see if the listener
has
+already been added. Multiple calls passing the same combination of eventName
+and listener
will result in the listener
being added, and called, multiple times.
server.prependListener('connection', (stream) => {
console.log('someone connected!');
});
+
+
+Returns a reference to the EventEmitter
, so that calls can be chained.
The name of the event.
+The callback function
+Rest
...args: any[]Adds a one-timelistener
function for the event named eventName
to the beginning of the listeners array. The next time eventName
is triggered, this
+listener is removed, and then invoked.
server.prependOnceListener('connection', (stream) => {
console.log('Ah, we have our first user!');
});
+
+
+Returns a reference to the EventEmitter
, so that calls can be chained.
The name of the event.
+The callback function
+Rest
...args: any[]Returns a copy of the array of listeners for the event named eventName
,
+including any wrappers (such as those created by .once()
).
import { EventEmitter } from 'node:events';
const emitter = new EventEmitter();
emitter.once('log', () => console.log('log once'));
// Returns a new Array with a function `onceWrapper` which has a property
// `listener` which contains the original listener bound above
const listeners = emitter.rawListeners('log');
const logFnWrapper = listeners[0];
// Logs "log once" to the console and does not unbind the `once` event
logFnWrapper.listener();
// Logs "log once" to the console and removes the listener
logFnWrapper();
emitter.on('log', () => console.log('log persistently'));
// Will return a new Array with a single function bound by `.on()` above
const newListeners = emitter.rawListeners('log');
// Logs "log persistently" twice
newListeners[0]();
emitter.emit('log');
+
+
+Removes all listeners, or those of the specified eventName
.
It is bad practice to remove listeners added elsewhere in the code,
+particularly when the EventEmitter
instance was created by some other
+component or module (e.g. sockets or file streams).
Returns a reference to the EventEmitter
, so that calls can be chained.
Optional
eventName: string | symbolRemoves the specified listener
from the listener array for the event named eventName
.
const callback = (stream) => {
console.log('someone connected!');
};
server.on('connection', callback);
// ...
server.removeListener('connection', callback);
+
+
+removeListener()
will remove, at most, one instance of a listener from the
+listener array. If any single listener has been added multiple times to the
+listener array for the specified eventName
, then removeListener()
must be
+called multiple times to remove each instance.
Once an event is emitted, all listeners attached to it at the
+time of emitting are called in order. This implies that any removeListener()
or removeAllListeners()
calls after emitting and before the last listener finishes execution
+will not remove them fromemit()
in progress. Subsequent events behave as expected.
import { EventEmitter } from 'node:events';
class MyEmitter extends EventEmitter {}
const myEmitter = new MyEmitter();
const callbackA = () => {
console.log('A');
myEmitter.removeListener('event', callbackB);
};
const callbackB = () => {
console.log('B');
};
myEmitter.on('event', callbackA);
myEmitter.on('event', callbackB);
// callbackA removes listener callbackB but it will still be called.
// Internal listener array at time of emit [callbackA, callbackB]
myEmitter.emit('event');
// Prints:
// A
// B
// callbackB is now removed.
// Internal listener array [callbackA]
myEmitter.emit('event');
// Prints:
// A
+
+
+Because listeners are managed using an internal array, calling this will
+change the position indices of any listener registered after the listener
+being removed. This will not impact the order in which listeners are called,
+but it means that any copies of the listener array as returned by
+the emitter.listeners()
method will need to be recreated.
When a single function has been added as a handler multiple times for a single
+event (as in the example below), removeListener()
will remove the most
+recently added instance. In the example the once('ping')
listener is removed:
import { EventEmitter } from 'node:events';
const ee = new EventEmitter();
function pong() {
console.log('pong');
}
ee.on('ping', pong);
ee.once('ping', pong);
ee.removeListener('ping', pong);
ee.emit('ping');
ee.emit('ping');
+
+
+Returns a reference to the EventEmitter
, so that calls can be chained.
Rest
...args: any[]By default EventEmitter
s will print a warning if more than 10
listeners are
+added for a particular event. This is a useful default that helps finding
+memory leaks. The emitter.setMaxListeners()
method allows the limit to be
+modified for this specific EventEmitter
instance. The value can be set to Infinity
(or 0
) to indicate an unlimited number of listeners.
Returns a reference to the EventEmitter
, so that calls can be chained.
PokerTableConfig
Represents the configuration settings necessary to define a poker table within a PokerRoom
. This interface
+standardizes essential properties such as unique identifiers, table size, and betting values, ensuring each
+table is set up with consistent and clear parameters.
The PokerTableConfig
interface provides a structured configuration for each table within a poker room. By defining
+specific parameters for table size, small blind, and big blind amounts, this interface supports accurate table setup
+and improves the consistency of poker gameplay within the Casino system.
id
and name
properties enable unique identification and labeling of tables.smallBlind
specify the betting increments for the table.size
defines the maximum number of players per table.PokerTableConfig
objects are typically used during table creation or setup, offering a clear and consistent way
+to configure and manage individual poker tables within a room.
id
,name
, size
and smallBlind
are not strictly required.Optional
idExample 1:
+const tableConfig: PokerTableConfig = {
id: "table42",
name: "High Stakes Table",
size: 6,
smallBlind: 100
};
console.log(tableConfig.id);
// Console Output: "table42"
+
+
+Example 2:
+const tableConfig: PokerTableConfig = {
id: undefined,
name: "Standard Table",
size: 4,
smallBlind: 10
};
console.log(tableConfig.id);
// Console Output: undefined
+
+
+Optional
nameOptional
sizeOptional
smallPokerTableInterface
+Represents a PokerTable within a PokerRoom.
+The PokerTable manages player seats, tracks the dealer, small blind, and big blind positions,
+and handles the start and stop of the PokerGame.
Optional
[captureRest
...args: AnyRestAlias for emitter.on(eventName, listener)
.
Rest
...args: any[]Synchronously calls each of the listeners registered for the event named eventName
, in the order they were registered, passing the supplied arguments
+to each.
Returns true
if the event had listeners, false
otherwise.
import { EventEmitter } from 'node:events';
const myEmitter = new EventEmitter();
// First listener
myEmitter.on('event', function firstListener() {
console.log('Helloooo! first listener');
});
// Second listener
myEmitter.on('event', function secondListener(arg1, arg2) {
console.log(`event with parameters ${arg1}, ${arg2} in second listener`);
});
// Third listener
myEmitter.on('event', function thirdListener(...args) {
const parameters = args.join(', ');
console.log(`event with parameters ${parameters} in third listener`);
});
console.log(myEmitter.listeners('event'));
myEmitter.emit('event', 1, 2, 3, 4, 5);
// Prints:
// [
// [Function: firstListener],
// [Function: secondListener],
// [Function: thirdListener]
// ]
// Helloooo! first listener
// event with parameters 1, 2 in second listener
// event with parameters 1, 2, 3, 4, 5 in third listener
+
+
+Rest
...args: AnyRestReturns an array listing the events for which the emitter has registered
+listeners. The values in the array are strings or Symbol
s.
import { EventEmitter } from 'node:events';
const myEE = new EventEmitter();
myEE.on('foo', () => {});
myEE.on('bar', () => {});
const sym = Symbol('symbol');
myEE.on(sym, () => {});
console.log(myEE.eventNames());
// Prints: [ 'foo', 'bar', Symbol(symbol) ]
+
+
+getSeats
+Starts a new PokerGame if there are at least two active players at the PokerTable.
+This method initiates the game flow, including assigning blinds and starting the rounds.
Validates if a specified index is within the valid bounds of the Casino’s room list.
+N/A
N/A
Prevents out-of-bounds errors by confirming that an index is within the acceptable range for the Casino’s +room list, ensuring that subsequent calls to access rooms by index have a valid target.
+N/A
index
: A zero-based integer specifying the position of a room within the Casino's managed room list.index
must be a non-negative integer within the bounds of the __rooms
array.true
if the index is within bounds.Error
if the index is out of bounds.Call this method before performing operations involving indexed access to rooms, ensuring the index +falls within valid boundaries.
+The zero-based index to validate within the room list.
+true
if the index is within bounds.Returns the number of listeners listening for the event named eventName
.
+If listener
is provided, it will return how many times the listener is found
+in the list of the listeners of the event.
The name of the event being listened for
+Optional
listener: FunctionThe event handler function
+Returns a copy of the array of listeners for the event named eventName
.
server.on('connection', (stream) => {
console.log('someone connected!');
});
console.log(util.inspect(server.listeners('connection')));
// Prints: [ [Function] ]
+
+
+Alias for emitter.removeListener()
.
Rest
...args: any[]Adds the listener
function to the end of the listeners array for the event
+named eventName
. No checks are made to see if the listener
has already
+been added. Multiple calls passing the same combination of eventName
and
+listener
will result in the listener
being added, and called, multiple times.
server.on('connection', (stream) => {
console.log('someone connected!');
});
+
+
+Returns a reference to the EventEmitter
, so that calls can be chained.
By default, event listeners are invoked in the order they are added. The emitter.prependListener()
method can be used as an alternative to add the
+event listener to the beginning of the listeners array.
import { EventEmitter } from 'node:events';
const myEE = new EventEmitter();
myEE.on('foo', () => console.log('a'));
myEE.prependListener('foo', () => console.log('b'));
myEE.emit('foo');
// Prints:
// b
// a
+
+
+The name of the event.
+The callback function
+Rest
...args: any[]Adds a one-time listener
function for the event named eventName
. The
+next time eventName
is triggered, this listener is removed and then invoked.
server.once('connection', (stream) => {
console.log('Ah, we have our first user!');
});
+
+
+Returns a reference to the EventEmitter
, so that calls can be chained.
By default, event listeners are invoked in the order they are added. The emitter.prependOnceListener()
method can be used as an alternative to add the
+event listener to the beginning of the listeners array.
import { EventEmitter } from 'node:events';
const myEE = new EventEmitter();
myEE.once('foo', () => console.log('a'));
myEE.prependOnceListener('foo', () => console.log('b'));
myEE.emit('foo');
// Prints:
// b
// a
+
+
+The name of the event.
+The callback function
+Rest
...args: any[]Adds the listener
function to the beginning of the listeners array for the
+event named eventName
. No checks are made to see if the listener
has
+already been added. Multiple calls passing the same combination of eventName
+and listener
will result in the listener
being added, and called, multiple times.
server.prependListener('connection', (stream) => {
console.log('someone connected!');
});
+
+
+Returns a reference to the EventEmitter
, so that calls can be chained.
The name of the event.
+The callback function
+Rest
...args: any[]Adds a one-timelistener
function for the event named eventName
to the beginning of the listeners array. The next time eventName
is triggered, this
+listener is removed, and then invoked.
server.prependOnceListener('connection', (stream) => {
console.log('Ah, we have our first user!');
});
+
+
+Returns a reference to the EventEmitter
, so that calls can be chained.
The name of the event.
+The callback function
+Rest
...args: any[]Returns a copy of the array of listeners for the event named eventName
,
+including any wrappers (such as those created by .once()
).
import { EventEmitter } from 'node:events';
const emitter = new EventEmitter();
emitter.once('log', () => console.log('log once'));
// Returns a new Array with a function `onceWrapper` which has a property
// `listener` which contains the original listener bound above
const listeners = emitter.rawListeners('log');
const logFnWrapper = listeners[0];
// Logs "log once" to the console and does not unbind the `once` event
logFnWrapper.listener();
// Logs "log once" to the console and removes the listener
logFnWrapper();
emitter.on('log', () => console.log('log persistently'));
// Will return a new Array with a single function bound by `.on()` above
const newListeners = emitter.rawListeners('log');
// Logs "log persistently" twice
newListeners[0]();
emitter.emit('log');
+
+
+Removes all listeners, or those of the specified eventName
.
It is bad practice to remove listeners added elsewhere in the code,
+particularly when the EventEmitter
instance was created by some other
+component or module (e.g. sockets or file streams).
Returns a reference to the EventEmitter
, so that calls can be chained.
Optional
eventName: string | symbolRemoves the specified listener
from the listener array for the event named eventName
.
const callback = (stream) => {
console.log('someone connected!');
};
server.on('connection', callback);
// ...
server.removeListener('connection', callback);
+
+
+removeListener()
will remove, at most, one instance of a listener from the
+listener array. If any single listener has been added multiple times to the
+listener array for the specified eventName
, then removeListener()
must be
+called multiple times to remove each instance.
Once an event is emitted, all listeners attached to it at the
+time of emitting are called in order. This implies that any removeListener()
or removeAllListeners()
calls after emitting and before the last listener finishes execution
+will not remove them fromemit()
in progress. Subsequent events behave as expected.
import { EventEmitter } from 'node:events';
class MyEmitter extends EventEmitter {}
const myEmitter = new MyEmitter();
const callbackA = () => {
console.log('A');
myEmitter.removeListener('event', callbackB);
};
const callbackB = () => {
console.log('B');
};
myEmitter.on('event', callbackA);
myEmitter.on('event', callbackB);
// callbackA removes listener callbackB but it will still be called.
// Internal listener array at time of emit [callbackA, callbackB]
myEmitter.emit('event');
// Prints:
// A
// B
// callbackB is now removed.
// Internal listener array [callbackA]
myEmitter.emit('event');
// Prints:
// A
+
+
+Because listeners are managed using an internal array, calling this will
+change the position indices of any listener registered after the listener
+being removed. This will not impact the order in which listeners are called,
+but it means that any copies of the listener array as returned by
+the emitter.listeners()
method will need to be recreated.
When a single function has been added as a handler multiple times for a single
+event (as in the example below), removeListener()
will remove the most
+recently added instance. In the example the once('ping')
listener is removed:
import { EventEmitter } from 'node:events';
const ee = new EventEmitter();
function pong() {
console.log('pong');
}
ee.on('ping', pong);
ee.once('ping', pong);
ee.removeListener('ping', pong);
ee.emit('ping');
ee.emit('ping');
+
+
+Returns a reference to the EventEmitter
, so that calls can be chained.
Rest
...args: any[]Retrieves the total number of PokerRoom
instances currently managed by the Casino.
N/A
N/A
This method provides insight into the number of poker rooms that the Casino manages, supporting +validation for index-bound operations or general information on Casino state.
+N/A
N/A
N/A
Use this method to retrieve the total count of active poker rooms, which is helpful when iterating over +rooms or confirming index-bound conditions.
+By default EventEmitter
s will print a warning if more than 10
listeners are
+added for a particular event. This is a useful default that helps finding
+memory leaks. The emitter.setMaxListeners()
method allows the limit to be
+modified for this specific EventEmitter
instance. The value can be set to Infinity
(or 0
) to indicate an unlimited number of listeners.
Returns a reference to the EventEmitter
, so that calls can be chained.
Sets the name of the PokerRoom
, allowing the name to be updated or customized.
N/A
- This method is part of the PokerRoomInterface
and does not implement any external methods.
N/A
- This method does not override any superclass or parent methods.
The setName
method is used to assign a specific name to a PokerRoom
, which helps distinguish it within the system.
+This is essential for systems where rooms need to be identifiable and manageable through a unique name.
N/A
- No events are emitted by this method.
name
: A string representing the new name for the room. It must be a valid, non-empty string to ensure
+the room has a clear, identifiable label.name
parameter should be a non-empty string to provide meaningful identification.name
that was set for the PokerRoom
.Use this method to set or update the name of a room in a system where unique or identifiable room names +are necessary for reference.
+The new name for the PokerRoom
.
WRAPPER METHODS (UTILITY & CONVENIENCE)
+WRAPPER METHODS (UTILITY & CONVENIENCE)
+Const
logger
A singleton instance of the Logger
class. This instance is initialized once with the configuration provided by the config
+constant. The instance provides centralized logging across the application.
The logger
singleton offers consistent access to logging functionality, ensuring that all logs follow the specified
+configuration settings, such as the directory for log files and whether to enable console logging.
Import the logger
singleton directly wherever logging is required in the application.
+BaseEventEmitter
+Represents a base event emitter for handling poker-related events, particularly in managing multiple +poker rooms (PokerRooms
). This class is responsible for creating, listing, removing, and searching rooms, +emitting specific events related to these actions.Purpose
Acts as a central hub for organizing poker games, enabling the creation and management of poker rooms. Each room +can accommodate players and maintain its own game state. The
+BaseEventEmitter
also supports middleware-based event processing, +allowing for validation and transformation of events.Extends
Extends the Node.js
+EventEmitter
to emit events when specific actions occur, such as creating or removing a room.Implements
Implements the
+BaseEventEmitterInterface
, ensuring a consistent interface structure and predictable behavior +for all event emitters within the library.Events Overview
+- casino:roomCreated: Emitted when a new room is created, signaling listeners to respond to this action.
+- casino:roomRemoved: Emitted when a room is removed, signaling listeners to update or respond accordingly.
+
+Usage
This class can be instantiated to manage rooms, emit events for room-related actions, and handle middleware-based +processing for emitted events. It’s designed for easy integration into poker or casino game management.
+Example
+ +