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

io.activej.async.process.AsyncCloseable Maven / Gradle / Ivy

Go to download

A convenient way to organize asynchronous code. Promises are a faster and more efficient version of JavaScript's Promise and Java's CompletionStage's.

There is a newer version: 6.0-rc2
Show newest version
/*
 * Copyright (C) 2020 ActiveJ LLC.
 *
 * 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
 *
 * http://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.
 */

package io.activej.async.process;

import io.activej.async.exception.AsyncCloseException;
import io.activej.common.recycle.Recyclers;

import java.util.function.Consumer;

/**
 * Describes methods that are used to handle exceptional behaviour or to handle closing.
 * 

* After {@link #close()}, or {@link #closeEx(Exception)} is called, the following things * should be done: *

    *
  • Resources held by an object should be freed
  • *
  • All pending asynchronous operations should be completed exceptionally
  • *
* All operations of this interface are idempotent. */ public interface AsyncCloseable { Object STATIC = new Object() {{ Recyclers.register(AsyncCloseable.class, AsyncCloseable::close); }}; /** * Cancels the process. */ default void close() { closeEx(new AsyncCloseException()); } /** * Closes process exceptionally in case an exception * is thrown while executing the given process. * * @param e exception that is used to close process with */ void closeEx(Exception e); static AsyncCloseable of(Consumer exceptionConsumer) { return exceptionConsumer::accept; } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy