Single.zip with Completable

时间:2016-09-27 12:15:38

标签: rx-java

这是我的问题:我有一些单身,想拉链。但我只希望在Completable完成后调用zip函数。另外,我想同时订阅所有单曲和Completable。 (所以没有completable.andThen(Single.zip(...)

以下是我现在正在做的一个例子:

Single<T1> s1 = …;
Single<T2> s2 = …;
Single<T3> s3 = …;
Completable c = …;

Single.zip(s1, s2, s3, c.andThen(Single.just("")), (a, b, c, ignore) -> {
// All singles have emitted an item and c is completed
 …
})

有更好的方法吗?

1 个答案:

答案 0 :(得分:11)

import java.awt.Color; import java.awt.Dimension; import java.awt.Font; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.geom.Rectangle2D; import javax.swing.JComponent; import javax.swing.JFrame; import javax.swing.SwingUtilities; import javax.swing.WindowConstants; public class TestLine { public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { new TestLine().start(); } }); } private static void start() { JFrame frame = new JFrame(); frame.setContentPane(new CarthPanel()); frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); frame.pack(); frame.setVisible(true); } private static class CarthPanel extends JComponent { @Override public Dimension getPreferredSize() { return new Dimension(200, 200); } @Override protected void paintComponent(Graphics g) { Graphics2D gg = (Graphics2D) g; int w = gg.getClipBounds().width; int h = gg.getClipBounds().height; System.out.println("(w,h)=(" + w + "," + h + ")"); gg.translate(w - 1, 0); // <<< when uncommenting both lines, mirroring applies gg.scale(-1.0, 1.0); // paintTest(gg, w, h); } private static void paintTest(Graphics2D g, int w, int h) { // black background g.setColor(Color.black); g.fillRect(0, 0, w, h); // colored corners g.setColor(Color.RED); g.drawLine(0, 0, 10, 0); g.drawLine(0, 0, 0, 10); g.setColor(Color.RED); g.drawLine(0, 199, 10, 199); g.drawLine(0, 199, 0, 189); g.setColor(Color.CYAN); g.drawLine(189, 0, 199, 0); g.drawLine(199, 0, 199, 10); g.setColor(Color.CYAN); g.drawLine(189, 199, 199, 199); g.drawLine(199, 199, 199, 189); // yellow squares g.setColor(Color.yellow); g.drawRect(3, 3, 10, 10); g.fillRect(186, 3, 11, 11); g.fillRect(3, 186, 11, 11); g.drawRect(186, 186, 10, 10); String chars = "ABC"; g.setFont(Font.decode("Arial 72")); Rectangle2D rect = g.getFontMetrics().getStringBounds(chars, g); g.drawString(chars, (int) (200 - rect.getWidth()) / 2, (int) (200 - rect.getHeight())); } } } 转换为toSingleDefault时,您可以使用Completable

Single