control() waits for all incoming connections to emit.
The main usage of control() is as an AND gate between multiple sources:
  /*!*/import { wrap, control, group } from '@connectv/core';
import { fromEvent } from 'rxjs';

let b1 = document.getElementById('b1');
let b2 = document.getElementById('b2');

  wrap(fromEvent(b1, 'click')),
  wrap(fromEvent(b2, 'click'))
.subscribe(() => console.log('BOTH CLICKED!'));


If one source emits multiple times, control() will queue incoming emissions and pair them with emissions of other sources:
  /*!*/import { source, control, group } from '@connectv/core';

let a = source();
let b = source();

group(a, b)

/*!*/a.send('a1'); //--> queued
/*!*/a.send('a2'); //--> queued
/*!*/a.send('a3'); //--> queued
/*!*/b.send('b1'); //--> paired with 'a1'
/*!*/b.send('b2'); //--> paired with 'a2'
/*!*/b.send('b3'); //--> paired with 'a3'
As you can see, control() will emit an array of all paired values.


Some agents can have a control pin accessible on their .control property. This pin is not mentioned in their signature, and allows you to control behavior of an agent, for example by blocking it from responding until some conditions are met, etc.


In a gate() agent, the .control is used to allow something through or drop it:
  import { wrap, map, group, gate } from '@connectv/core';
import { fromEvent } from 'rxjs';

let i = document.getElementById('i') as HTMLInputElement;
/*!*/let submitGate = gate();

//--> so this validator checks if the length of input is proper
/*!*/let validator = map(v => v.length > 5 && v.length < 10);

wrap(fromEvent(i, 'input'))
.to(map(() => i.value))
.to(submitGate.input, validator);         //--> the value goes both to the gate and validator

/*!*/;         //--> the validator controls the gate

submitGate.output.subscribe(console.log); //--> gate submits (to console ;))


In a node() agent, such as expr(), .control property controls when the node is going to run:
  import { wrap, map, expr } from '@connectv/core';
import { fromEvent } from 'rxjs';

let a = document.getElementById('a') as HTMLInputElement;
let b = document.getElementById('b') as HTMLInputElement;
let btn = document.getElementById('btn');

/*!*/let e = expr((a, b) => a + b);

wrap(fromEvent(a, 'input')).to(map(() => parseInt(a.value))).to(;
wrap(fromEvent(b, 'input')).to(map(() => parseInt(b.value))).to(;
/*!*/wrap(fromEvent(btn, 'click')).to(e.control);  //--> so only add when the button is pressed


Further reading

Copied to Clipboard!