如何观察反向依赖顺序?
How to observe on reverse dependency order?
我想以反向依赖顺序观察对象树,但不知道要使用什么组合器。具体情况是遍历 AWS 资源以便删除,例如在删除 S3 对象之前删除 S3 对象,如下所示:
val S3 = new AmazonS3Client
val buckets = Observable.from {
S3.listBuckets.asScala
}
val objects = buckets.flatMap { b => Observable.from(
S3.listObjects(new ListObjectsRequest().withBucketName(b.getName))
.getObjectSummaries
.asScala)
}
val combined:Observable[_] = ???
for (thing <- combined) thing match {
case b:Bucket => println("delete bucket")
case o:S3ObjectSummary => println("delete object")
}
因此,最终的 combined
observable 应该在发出桶之前发出所有对象。我应该使用什么组合器?
您可以将 b
附加到其对象的末尾,例如,
val objects = buckets.flatMap { b => Observable.from(
S3.listObjects(new ListObjectsRequest().withBucketName(b.getName))
.getObjectSummaries
.asScala) :+ b
}
我想以反向依赖顺序观察对象树,但不知道要使用什么组合器。具体情况是遍历 AWS 资源以便删除,例如在删除 S3 对象之前删除 S3 对象,如下所示:
val S3 = new AmazonS3Client
val buckets = Observable.from {
S3.listBuckets.asScala
}
val objects = buckets.flatMap { b => Observable.from(
S3.listObjects(new ListObjectsRequest().withBucketName(b.getName))
.getObjectSummaries
.asScala)
}
val combined:Observable[_] = ???
for (thing <- combined) thing match {
case b:Bucket => println("delete bucket")
case o:S3ObjectSummary => println("delete object")
}
因此,最终的 combined
observable 应该在发出桶之前发出所有对象。我应该使用什么组合器?
您可以将 b
附加到其对象的末尾,例如,
val objects = buckets.flatMap { b => Observable.from(
S3.listObjects(new ListObjectsRequest().withBucketName(b.getName))
.getObjectSummaries
.asScala) :+ b
}