/** * Copyright 2026 Angus.Fenying * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * The strategy for handling time reversal events in time-based ID generation. */ export enum ETimeReversedStrategy { /** * Throw an error to stop the generator from generating IDs. * * - Pro: Stops ID generation immediately. * - Con: Only after the time catches up the previous time again, * the generator can continue to generate IDs. */ THROW_ERROR = 0, /** * Use the reversed time as the current time to generate IDs. * * - Pro: Allows the generator to continue generating IDs immediately. * - Con: The generated IDs may not be in the correct order, and the IDs generated * may not be unique if the time is reversed multiple times. */ USE_REVERSED_TIME = 1, /** * Use the previous time as the current time to generate IDs. * * - Pro: Allows the generator to continue generating IDs immediately, * and the IDs generated will be in the correct order. * - Con: The sequence number will run out quickly if the real time does * not catch up with the previous time soon. */ USE_PREVIOUS_TIME = 2, } /** * How should the generator handle the sequence number when the time changes. */ export enum ESequenceStrategy { /** * Reset the sequence number to 0 when the time changes. * * - Pro: The sequence number will not overflow and the IDs generated will always be in the correct order. * - Con: The randomness of the IDs will be reduced. */ RESET = 0, /** * Keep the sequence number unchanged when the time changes. * * - Pro: The randomness of the IDs will be preserved. * - Con: The sequence number may be reset to 0 if the sequence number overflows, * so the IDs generated in the same millisecond may not be in the correct order. */ KEEP_CURRENT = 1, }