Skip to content

Commit

Permalink
Set version to 9.0.488
Browse files Browse the repository at this point in the history
  • Loading branch information
niwinz committed Oct 17, 2022
1 parent 1e7d95c commit 2989b9f
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 6 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
# Changelog #


## Version 9.0.488

Date: 2022-10-17

- Add more usability fixes on concurrencly limiter



## Version 9.0.486

Date: 2022-10-17
Expand Down
9 changes: 9 additions & 0 deletions build.clj
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,21 @@
{:class-dir class-dir
:jar-file jar-file}))


(defn compile [_]
(b/javac {:src-dirs ["src"]
:class-dir class-dir
:basis basis
:javac-opts ["-source" "11" "-target" "11" "-Xlint:unchecked"]}))


(defn install [_]
(b/install {:basis basis
:lib lib
:version version
:jar-file jar-file
:class-dir class-dir}))

(defn clojars [_]
(b/process
{:command-args ["mvn"
Expand Down
4 changes: 2 additions & 2 deletions doc/user-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ A promise library for Clojure and ClojureScript.
Leiningen:

```clojure
[funcool/promesa "9.0.486"]
[funcool/promesa "9.0.488"]
```

deps.edn:

```clojure
funcool/promesa {:mvn/version "9.0.486"}
funcool/promesa {:mvn/version "9.0.488"}
```

On the JVM platform _promesa_ is built on top of *completable futures*
Expand Down
3 changes: 2 additions & 1 deletion src/promesa/exec.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -475,12 +475,13 @@
#?(:clj
(defn concurrency-limiter
"Create an instance of concurrencly limiter. EXPERIMENTAL"
[& {:keys [executor concurrency queue-size on-run on-poll]
[& {:keys [executor concurrency queue-size on-run on-poll on-queue]
:or {executor *default-executor*
concurrency 1
queue-size Integer/MAX_VALUE}}]
(let [^ExecutorService executor (resolve-executor executor)]
(doto (ConcurrencyLimiter. executor (int concurrency) (int queue-size))
(cond-> (fn? on-queue) (.setOnQueueCallback on-queue))
(cond-> (fn? on-run) (.setOnRunCallback on-run))
(cond-> (fn? on-poll) (.setOnPollCallback on-poll))))))

Expand Down
15 changes: 12 additions & 3 deletions src/promesa/exec/ConcurrencyLimiter.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public class ConcurrencyLimiter extends AFn implements IObj {
private final int maxQueueSize;
private IPersistentMap metadata = PersistentArrayMap.EMPTY;

protected IFn onQueueCallback;
protected IFn onRunCallback;
protected IFn onPollCallback;

Expand All @@ -61,6 +62,10 @@ public ConcurrencyLimiter(final ExecutorService executor,
this.limit = new Semaphore(maxConcurrency);
}

public void setOnQueueCallback(IFn f) {
this.onQueueCallback = f;
}

public void setOnRunCallback(IFn f) {
this.onRunCallback = f;
}
Expand Down Expand Up @@ -89,6 +94,10 @@ public CompletableFuture invoke(Object arg1) {
return result;
}

if (this.onQueueCallback != null) {
this.onQueueCallback.invoke();
}

this.executor.submit((Runnable)this);
return result;
}
Expand Down Expand Up @@ -196,10 +205,10 @@ public void run() {
return;
}

future.whenComplete((result, t) -> {
if (t != null) {
future.whenComplete((result, cause) -> {
if (cause != null) {
this.limiter.releaseAndSchedule();
this.result.completeExceptionally((Throwable)t);
this.result.completeExceptionally((Throwable)cause);
} else {
this.limiter.releaseAndSchedule();
this.result.complete(result);
Expand Down

0 comments on commit 2989b9f

Please sign in to comment.