use of il.ac.bgu.cs.bp.bpjs.exceptions.BProgramException in project BPjs by bThink-BGU.
the class BProgramSyncSnapshot method handleInterrupts.
private void handleInterrupts(BEvent anEvent, Iterable<BProgramRunnerListener> listeners, BProgram bprog, Context ctxt) {
Set<BThreadSyncSnapshot> interrupted = threadSnapshots.stream().filter(bt -> bt.getBSyncStatement().getInterrupt().contains(anEvent)).collect(toSet());
if (!interrupted.isEmpty()) {
threadSnapshots.removeAll(interrupted);
interrupted.forEach(bt -> {
listeners.forEach(l -> l.bthreadRemoved(bprog, bt));
bt.getInterrupt().ifPresent(func -> {
final Scriptable scope = bt.getScope();
// can't call bsync from a break handler.
scope.delete("bsync");
try {
ctxt.callFunctionWithContinuations(func, scope, new Object[] { anEvent });
} catch (ContinuationPending ise) {
throw new BProgramException("Cannot call bsync from a break-upon handler. Please consider pushing an external event.");
}
});
});
}
}
Aggregations