This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public <T> Mono<T> executeMono(Supplier<T> task) { | |
CompletableFuture<T> future = CompletableFuture.supplyAsync(task); | |
return Mono.fromFuture(future); | |
} | |
public <T> Flux<T> executeFlux(Supplier<List<T>> task) { | |
return Flux.create((sink) -> { | |
CompletableFuture<List<T>> future = CompletableFuture.supplyAsync(task); | |
future.whenComplete((list, exception) -> { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String result = CompletableFuture.supplyAsync(() -> "1 + 2 = " + (1 + 2)).get(); | |
System.out.printl(result); | |
// Output | |
1 + 2 = 3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import reactor.core.publisher.Flux; | |
import reactor.core.publisher.Mono; | |
import java.util.ArrayList; | |
import java.util.List; | |
import java.util.Random; | |
import java.util.concurrent.CompletableFuture; | |
import java.util.function.Supplier; | |
class Test { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class LongRunningTaskService { | |
public <T> CompletableFuture<T> executeCompletableFuture(Supplier<T> task) { | |
CompletableFuture<T> completableFuture = new CompletableFuture<>(); | |
new Thread(() -> { | |
try { | |
System.out.println("Do something before task execution ..."); | |
completableFuture.complete(task.get()); | |
System.out.println("Do something after task execution ..."); | |
} catch (Exception exception) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Future<void> _requestTrackPositions( | |
String correlationId, String deviceId, String station, String trackNumber) async { | |
_messagingService.request( | |
topicRetrieveTrackPositionsQuery, | |
jsonEncode(RetrieveTrackPositionsQuery( | |
mobileDeviceId: deviceId, | |
correlationId: correlationId, | |
station: station, | |
trackNumber: trackNumber))); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
final RequestReplyService requestReplyService = RequestReplyService(); | |
// request track positions and wait for received response | |
final TrackPositionsRetrievedResponse response = await requestReplyService.execute( | |
request: () => _requestTrackPositions(correlationId, mobileDeviceId, station, trackNumber), | |
response: () => _trackPositionRetrieved$(correlationId, mobileDeviceId)); | |
// do something with response ... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:mqtt_client/mqtt_client.dart'; | |
import 'package:rxdart/rxdart.dart'; | |
class MessagingService { | |
/// Subscribes to the given topic and produces a stream of received updates from the message | |
/// broker matching this topic. You can also pass [MqttQos] which defaults to atLeastOnce. | |
/// | |
/// This method returns a stream of [MqttMessage] instances. | |
Stream<MqttMessage> updatesFor(String topic, [MqttQos qos = MqttQos.atLeastOnce]) { | |
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:async'; | |
import 'package:flutter/foundation.dart'; | |
/// This class allows request-reply communication over messaging. | |
class RequestReplyService { | |
StreamSubscription _subscription; | |
/// release resources | |
void dispose() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Component({ | |
selector: 'app-identify-device', | |
template: ` | |
... | |
<form (submit)="identifyDevice()" [formGroup]="formGroup"> | |
<ion-item> | |
<ion-label color="dark" [position]="'stacked'">Track Number</ion-label> | |
<ion-input clearInput type="text" formControlName="trackNumber"></ion-input> | |
</ion-item> | |
</form> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Injectable({ | |
providedIn: 'root' | |
}) | |
export class LoggedInGuard implements CanActivate { | |
protected constructor(private _router: Router, _store: CoreStore) { } | |
public canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Promise<boolean> { | |
return this._store.ready$.then(() => this.toResult(), () => this.toResult()); | |
} |