export function getAll() {
  return vanadium.init().then((runtime) => {
    var namespace = runtime.getNamespace();
    var ctx = runtime.getContext().withTimeout(5000);
    ctx.waitUntilDone(function(){});

    var nsPrefix = runtime.accountName.replace('dev.v.io/u/', 'users/');
    var globPattern = vanadium.naming.join(nsPrefix, 'p2b/*');
    var globResult = namespace.glob(ctx, globPattern);
    var p2bServices = [];
    globResult.stream.on('data', (p2bServiceName) => {
      p2bServices.push(p2bServiceName.name);
    });

    // wait until all the data arrives then return the collection
    return globResult.then(() => {
      ctx.cancel();
      return p2bServices;
    });
  }).catch((err) => {
    if (err instanceof vanadium.verror.ExtensionNotInstalledError) {
      vanadium.extension.promptUserToInstallExtension();
    } else {
      throw err;
    }
  });
}
export function pipe(name, stream) {
  return vanadium.init().then((runtime) => {
    var client = runtime.getClient();
    var ctx = runtime.getContext().withTimeout(5000);
    ctx.waitUntilDone(function(){});
    return client.bindTo(ctx, name).then((remote) => {
      var remoteStream = remote.pipe(ctx).stream;
      stream.pipe(remoteStream);
      return Promise.resolve();
    });
  }).catch((err) => {
    if (err instanceof vanadium.verror.ExtensionNotInstalledError) {
      vanadium.extension.promptUserToInstallExtension();
    } else {
      throw err;
    }
  });
}