azukiapp/azk

View on GitHub
src/agent/tools.js

Summary

Maintainability
A
0 mins
Test Coverage
import { log } from 'azk';
import { publish } from 'azk/utils/postal';
import { async, defer } from 'azk/utils/promises';

var Tools = {
  change_status(key, status, data) {
    var keys = ["commands", key, "status", status];
    (status != "error") ?  log.info_t(keys, data) : null;
    publish("agent." + key + ".status", { type: "status", context: key, status: status, data: data });
  },

  defer_status(key, func) {
    return defer((resolve, reject) => {
      return func(resolve, reject, (status, data) => {
        this.change_status(key, status, data);
      });
    });
  },

  async_status(key, ...args) {
    args.push((status, data) => {
      this.change_status(key, status, data);
    });
    return async(...args);
  },
};

export { Tools };