createPromiseLogic()

Factory FunctionCreate custom PromiseLogic instance with method name customization

createPromiseLogic() is a factory function used to create custom PromiseLogic instances. Through configuration options, you can customize method names to better fit your project's naming conventions and business requirements.

All methods in custom instances return PromiseWithTimer instances which wrap native Promise and provide additional functionality like timeout control.

Syntax

javascript
 createPromiseLogic(options?)

Parameters

ParameterTypeDescription
optionsCreatePromiseLogicOptionsConfiguration options for customizing instance behavior and naming

Configuration Option Properties

ParameterTypeDescription
prefixstringMethod name prefix, e.g. "async" will generate asyncAnd, asyncOr, etc.
suffixstringMethod name suffix, e.g. "Logic" will generate andLogic, orLogic, etc.
renameRecord<string, string>Custom rename mapping, e.g. { and: "conjunction", or: "disjunction" }

Return Value

Returns a custom PromiseLogic instance containing configured methods. All methods return PromiseWithTimer instances.

PromiseLogicInstance

Behavior

Creation Successful

Successfully creates a custom PromiseLogic instance containing configured methods.

Special Case

The createPromiseLogic method never fails, always returns a valid PromiseLogic instance.

Examples

Basic Usage

Create default PromiseLogic instance

JAVASCRIPT
Loading...

Timeout Control

Use maxTimer with custom instance

JAVASCRIPT
Loading...

Add Prefix

Create instance with prefixed method names

JAVASCRIPT
Loading...

Add Suffix

Create instance with suffixed method names

JAVASCRIPT
Loading...

Custom Rename

Fully customize method names

JAVASCRIPT
Loading...

Combined Configuration

Combine prefix, suffix, and rename

JAVASCRIPT
Loading...

Real Application

Organize different logic groups in project

JAVASCRIPT
Loading...

Naming Rules

Method Name Generation Rules

Priority Order

  1. 1. First check if there is a custom name in rename configuration
  2. 2. If not, apply prefix + original name + suffix rule
  3. 3. If none configured, use default name

Example

javascript
// Configuration: { prefix: 'async', suffix: 'Logic', rename: { and: 'conjunction' } }

// Generated method names:
// and → asyncConjunctionLogic (rename priority)
// or → asyncOrLogic (prefix + or + suffix)
// xor → asyncXorLogic (prefix + xor + suffix)
// Other methods follow same pattern...

Important Notes

  • createPromiseLogic is used to create custom PromiseLogic instances, supporting method name customization
  • All methods in custom instances return PromiseWithTimer which supports maxTimer() for timeout control
  • maxTimer can only detect timeout, cannot cancel Promise operation itself
  • Can use prefix, suffix, and rename configurations simultaneously, configurations are applied in order
  • Methods not specified in rename will use default naming rules (prefix + original name + suffix)
  • Custom instances have the same functionality and behavior as default PromiseLogic
  • Suitable for projects that need to use different naming conventions in different business scenarios
  • Can be used for code organization, namespace isolation, team standard unification, etc.