channel-future.js 735 B

123456789101112131415161718192021222324
  1. const facts = __host.channel("facts");
  2. const anonymous = __host.channel();
  3. __host.enterPhase("gather");
  4. const research = __host.future(async () => {
  5. try {
  6. const found = await __host.ask("ask#1", __host.createActor("actor#1", "researcher"), "find facts");
  7. for (const fact of found)
  8. facts.send(fact);
  9. }
  10. finally {
  11. facts.close();
  12. }
  13. });
  14. __host.enterPhase("verify");
  15. const verify = __host.future(async () => {
  16. const verdicts = [];
  17. for await (const fact of facts) {
  18. verdicts.push(await __host.ask("ask#2", __host.createActor("actor#2", `verifier-${fact.claim}`), `verify ${fact.claim}`));
  19. }
  20. anonymous.close();
  21. return verdicts;
  22. });
  23. await research;
  24. return verify;