TODO(arv): Change CodeUnit to use promises instead of "events".