Skip to content

Commit 99bed3c

Browse files
committed
feat: Add implementation, tests, and docs
0 parents  commit 99bed3c

123 files changed

Lines changed: 10185 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
# Created by https://www.toptal.com/developers/gitignore
2+
3+
### Intellij ###
4+
5+
.idea/**
6+
!.idea/codeStyles
7+
!.idea/codeStyles/codeStyleConfig.xml
8+
!.idea/codeStyles/Project.xml
9+
10+
# Gradle and Maven with auto-import
11+
# When using Gradle or Maven with auto-import, you should exclude module files,
12+
# since they will be recreated, and may cause churn. Uncomment if using
13+
# auto-import.
14+
# .idea/artifacts
15+
# .idea/compiler.xml
16+
# .idea/jarRepositories.xml
17+
# .idea/modules.xml
18+
# .idea/*.iml
19+
# .idea/modules
20+
# *.iml
21+
# *.ipr
22+
23+
# File-based project format
24+
*.iws
25+
26+
# IntelliJ
27+
out/
28+
!**/port/out/
29+
30+
# mpeltonen/sbt-idea plugin
31+
.idea_modules/
32+
33+
# JIRA plugin
34+
atlassian-ide-plugin.xml
35+
36+
### Java ###
37+
# Compiled class file
38+
*.class
39+
40+
# Log file
41+
*.log
42+
*.log.gz
43+
*.tmp
44+
logs/
45+
46+
# Package Files #
47+
*.jar
48+
*.war
49+
*.nar
50+
*.ear
51+
*.zip
52+
*.tar.gz
53+
*.rar
54+
55+
### VisualStudioCode ###
56+
.vscode/*
57+
!.vscode/settings.json
58+
!.vscode/tasks.json
59+
!.vscode/launch.json
60+
!.vscode/extensions.json
61+
!.vscode/*.code-snippets
62+
63+
# Local History for Visual Studio Code
64+
.history/
65+
66+
# Built Visual Studio Code Extensions
67+
*.vsix
68+
69+
### VisualStudioCode Patch ###
70+
# Ignore all local history of files
71+
.history
72+
.ionide
73+
74+
### Gradle ###
75+
.gradle
76+
**/build/
77+
!src/**/build/
78+
79+
# Ignore Gradle GUI config
80+
gradle-app.setting
81+
82+
# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
83+
!gradle-wrapper.jar
84+
85+
# Avoid ignore Gradle wrappper properties
86+
!gradle-wrapper.properties
87+
88+
# Cache of project
89+
.gradletasknamecache
90+
91+
# Eclipse Gradle plugin generated files
92+
# Eclipse Core
93+
.project
94+
# JDT-specific (Eclipse Java Development Tools)
95+
.classpath
96+
97+
### Gradle Patch ###
98+
# Java heap dump
99+
*.hprof

.idea/codeStyles/Project.xml

Lines changed: 82 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/codeStyles/codeStyleConfig.xml

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.run/publishToMavenLocal.run.xml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<component name="ProjectRunConfigurationManager">
2+
<configuration default="false" name="publishToMavenLocal" type="GradleRunConfiguration" factoryName="Gradle">
3+
<ExternalSystemSettings>
4+
<option name="executionName" />
5+
<option name="externalProjectPath" value="$PROJECT_DIR$" />
6+
<option name="externalSystemIdString" value="GRADLE" />
7+
<option name="scriptParameters" value="" />
8+
<option name="taskDescriptions">
9+
<list />
10+
</option>
11+
<option name="taskNames">
12+
<list>
13+
<option value="publishToMavenLocal" />
14+
</list>
15+
</option>
16+
<option name="vmOptions" />
17+
</ExternalSystemSettings>
18+
<ExternalSystemDebugServerProcess>true</ExternalSystemDebugServerProcess>
19+
<ExternalSystemReattachDebugProcess>true</ExternalSystemReattachDebugProcess>
20+
<DebugAllEnabled>false</DebugAllEnabled>
21+
<RunAsTest>false</RunAsTest>
22+
<method v="2" />
23+
</configuration>
24+
</component>

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2024 Alexander Mezhov
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Asynchronizer
2+
3+
![Asynchronizer](logo-128.png)
4+
5+
Java Concurrent API does not have enough to develop asynchronous code and work with it comfortably.
6+
Every time we have to invent something, otherwise the business logic can be obscured by all the technical
7+
details needed to support asynchronicity. The library provides a set of tools that aim to simplify
8+
development of asynchronous components, make their code easy-to-read and expressive, and clean
9+
the logic from technical details as much as possible.
10+
11+
For example, an implementation of the `git pull` command might look like this:
12+
13+
```java
14+
CompletableFuture<Void> pull(String repository) {
15+
var localRepository = new LocalRepository(repository);
16+
var remoteRepository = new RemoteRepository(repository);
17+
18+
return AsyncPipeline
19+
// Getting the latest commit of the local repository
20+
.supply(flow -> localRepository.getLastCommit())
21+
// Loading a set of new commits from the remote repository
22+
.await((flow, lastCommit) -> remoteRepository.loadCommitsSince(lastCommit))
23+
// Saving the new commits to the local repository
24+
.await((flow, remoteCommits) -> localRepository.saveCommits(remoteCommits))
25+
.toCompletableFuture();
26+
}
27+
```
28+
29+
## Documentation
30+
31+
* [Usage Guide](docs/README.md)

README.ru.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Asynchronizer
2+
3+
![Asynchronizer](logo-128.png)
4+
5+
Java Concurrent API не предоставляет достаточных возможностей для комфортной разработки
6+
асинхронного кода и работы с ним. Всякий раз приходится что-то изобретать, иначе прикладная
7+
логика может потеряться на фоне обилия технических деталей, необходимых для поддержки асинхронности.
8+
Библиотека предоставляет набор средств, нацеленных на упрощение разработки асинхронных компонентов,
9+
сделать их код более понятным и выразительным, максимально очистить логику от технических деталей.
10+
11+
Например, реализация команды `git pull` могла бы выглядеть так:
12+
13+
```java
14+
CompletableFuture<Void> pull(String repository) {
15+
var localRepository = new LocalRepository(repository);
16+
var remoteRepository = new RemoteRepository(repository);
17+
18+
return AsyncPipeline
19+
// Получение последнего комита в локальном репозитории
20+
.supply(flow -> localRepository.getLastCommit())
21+
// Загрузка новых комитов из удаленного репозитория
22+
.await((flow, lastCommit) -> remoteRepository.loadCommitsSince(lastCommit))
23+
// Сохранение новых комитов в локальном репозитории
24+
.await((flow, remoteCommits) -> localRepository.saveCommits(remoteCommits))
25+
.toCompletableFuture();
26+
}
27+
```
28+
29+
## Документация
30+
31+
* [Руководство по использованию](docs/README.ru.md)

asynchronizer/build.gradle.kts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
dependencies {
2+
implementation(libs.slf4j.api)
3+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package ru.asynchronizer.util;
2+
3+
/**
4+
* Defines the {@link #dispose()} method must be invoked on the service scope destroying.
5+
*/
6+
public interface IDisposable extends AutoCloseable {
7+
8+
void dispose();
9+
10+
11+
@Override
12+
default void close() {
13+
dispose();
14+
}
15+
16+
17+
default IDisposable andThen(IDisposable after) {
18+
return () -> {
19+
dispose();
20+
after.dispose();
21+
};
22+
}
23+
24+
25+
static IDisposable combine(Iterable<? extends IDisposable> items) {
26+
return () -> dispose(items);
27+
}
28+
29+
static IDisposable combine(IDisposable... items) {
30+
return () -> dispose(items);
31+
}
32+
33+
34+
static void dispose(Iterable<? extends IDisposable> items) {
35+
if (items != null) {
36+
for (var i : items) {
37+
if (i != null) {
38+
i.dispose();
39+
}
40+
}
41+
}
42+
}
43+
44+
static void dispose(IDisposable... items) {
45+
if (items != null) {
46+
for (var i : items) {
47+
if (i != null) {
48+
i.dispose();
49+
}
50+
}
51+
}
52+
}
53+
}

0 commit comments

Comments
 (0)