All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.azure.identity.implementation.SynchronizedAccessor Maven / Gradle / Ivy

The newest version!
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.azure.identity.implementation;

import reactor.core.publisher.Mono;

import java.time.Duration;
import java.util.function.Supplier;

/**
 * Synchronizes reactor threads accessing/instantiating a common value {@code T}.
 *
 * @param  The value being instantiated / accessed.
 */
public class SynchronizedAccessor {
    private Mono monoCache;

    public SynchronizedAccessor(Supplier> supplier) {
        monoCache = supplier.get().cache();
    }

    public SynchronizedAccessor(Supplier> supplier, Duration cacheTimeout) {
        monoCache = supplier.get().cache(cacheTimeout);
    }

    /**
     * Get the value from the configured supplier.
     *
     * @return the output {@code T}
     */
    public Mono getValue() {
        return monoCache;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy