Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add variable stop, start and transform methods #88

Merged
merged 2 commits into from
Sep 10, 2023

Conversation

Aylur
Copy link
Owner

@Aylur Aylur commented Sep 9, 2023

this introdues these to ags.Variable

const variable = ags.Variable(null, {
    // can be a string or string[] like before
    listen: 'path-to-script',
    listen: ['bash', '-c', 'some-bash-command'],
    poll: [5000, 'some-command-or-script'],
    poll: [5000, ['bash', '-c', 'some-command']],

    // now you can pass a transform method
    listen: ['path-to-script', out => JSON.parse(out)],
    listen: [['bash', '-c', 'some-bash-command'], out => JSON.parse(out)],
    poll: [5000, 'some-command-or-script', out => JSON.parse(out)],
    poll: [5000, ['bash', '-c', 'some-command'], out => JSON.parse(out)]
});

// temporarily stop them
variable.stopListen(); // this kills the subprocess
variable.stopPoll();

// start them
variable.startListen(); // launches the subprocess again 
variable.startPoll();

// get if they are active
print(variable.isListening);
print(variable.isPolling);

// cpu usage for example
const cpu = ags.Variable(0, {
    poll: [5000, 'top -b -n 1', out => out.split('\n')
        .find(line => line.includes('Cpu(s)'))
        .split(/\s+/)[1]],
});

@Aylur Aylur changed the title add variable stop and start methods add variable stop, start and transform methods Sep 9, 2023
@Aylur Aylur merged commit 0770a8b into main Sep 10, 2023
2 checks passed
Aylur added a commit to AhmedSaadi0/ags that referenced this pull request Sep 10, 2023
* add variable stop and start methods

* add transform method option
@Aylur Aylur deleted the feature/stop-and-start-variables branch September 10, 2023 16:09
Aylur added a commit that referenced this pull request Sep 10, 2023
* add variable stop and start methods

* add transform method option
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant