jextract/jni: Propagate CompletableFuture cancellation to Swift tasks

Abierto
#947 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
54/100
Tipo de issue
Nueva funcionalidad
Claridad
Bastante claro
Estado de actividad
Activo
Stack tecnológico
java, swift
Área
mobile-dev

Línea de trabajo

Start by tracing the JNI async call and generated thenApply result-conversion stage described in the issue, then review the reference workaround in the linked pull request. Check how cancellation reaches the source future and the Swift task; done means cancelling the returned Java future forwards cancellation to the Swift task so cooperative operations such as Task.sleep can observe it.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

Problem

Cancelling a future returned by a JNI async call currently changes only the Java future's state. The underlying Swift task keeps running. The generated thenApply result-conversion stage also prevents cancellation of the returned future from reaching the source future.

Example

public func waitForWork() async throws -> Int64 {
  try await Task.sleep(for: .seconds(60))
  return 1
}

A Java caller can cancel the returned future:

var future = MySwiftLibrary.waitForWork();
future.cancel(false);

The Java future is cancelled, but the Swift task continues running. Cancellation of the returned future should also be forwarded to the Swift task, so cancellation-aware operations such as Task.sleep can observe it.

Swift cancellation is cooperative: forwarding cancellation does not interrupt an operating-system thread or wait for the task to finish.

Reference workaround implementation: https://github.com/qoncept/swift-java/pull/10

Lenguaje dominante
Swift
Estrellas
1.3k
Forks
127
Merge medio
2 d 14 h
PR fusionados (30 d)
5

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de swiftlang/swift-java

Todos los issues de swiftlang/swift-java

Issues similares

Más issues de Swift

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.