@Override public Strand newStrand(SuspendableCallable<?> target) { return ff.newFiber(target); } };
/** * Spawns a fiber that transforms values read from the {@code in} channel and writes values to the {@code out} channel. * <p> * @param <S> the message type of the input (source) channel. * @param <T> the message type of the output (target) channel. * @param fiberFactory will be used to create the fiber * @param in the input channel * @param out the output channel * @param transformer the transforming operation */ public static <S, T> void fiberTransform(FiberFactory fiberFactory, final ReceivePort<S> in, final SendPort<T> out, final SuspendableAction2<? extends ReceivePort<? super S>, ? extends SendPort<? extends T>> transformer) { fiberFactory.newFiber(new SuspendableCallable<Void>() { @Override public Void run() throws SuspendExecution, InterruptedException { try { ((SuspendableAction2) transformer).call(in, out); out.close(); } catch (ProducerException e) { out.close(e.getCause()); } catch (Throwable t) { out.close(t); } return null; } }).start(); }
/** * Starts a new fiber using the given scheduler and runs the actor in it. * The fiber's name will be set to this actor's name. * * @param ff the {@link FiberFactory factory} (or {@link FiberScheduler scheduler}) that will be used to create the actor's fiber. * @return This actors' ActorRef */ public ActorRef<Message> spawn(FiberFactory ff) { if (ff == null) return spawn(); checkReplacement(); ff.newFiber(runner).setName(getName()).start(); return ref(); }