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

io.datakernel.csp.ChannelInput Maven / Gradle / Ivy

Go to download

Communicating sequential process via channels, similar to Golang's channels. A channel could be imagine as a pipe which connects some processes.

The newest version!
/*
 * Copyright (C) 2015-2018 SoftIndex 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.datakernel.csp;

import io.datakernel.csp.dsl.ChannelSupplierTransformer;
import io.datakernel.csp.queue.ChannelQueue;
import io.datakernel.csp.queue.ChannelZeroBuffer;
import io.datakernel.promise.Promise;

import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Predicate;

@FunctionalInterface
public interface ChannelInput {
	Promise set(ChannelSupplier input);

	default ChannelConsumer getConsumer() {
		return getConsumer(new ChannelZeroBuffer<>());
	}

	default ChannelConsumer getConsumer(ChannelQueue queue) {
		Promise extraAcknowledge = set(queue.getSupplier());
		return queue.getConsumer(extraAcknowledge);
	}

	default  ChannelInput transformWith(ChannelSupplierTransformer> fn) {
		return input -> set(fn.transform(input));
	}

	default  ChannelInput map(Function fn) {
		return input -> set(input.map(fn));
	}

	default  ChannelInput mapAsync(Function> fn) {
		return input -> set(input.mapAsync(fn));
	}

	default ChannelInput filter(Predicate predicate) {
		return input -> set(input.filter(predicate));
	}

	default ChannelInput peek(Consumer peek) {
		return input -> set(input.peek(peek));
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy