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

Experiment with better "module" import guards #238

Open
Ash258 opened this issue Dec 4, 2021 · 5 comments
Open

Experiment with better "module" import guards #238

Ash258 opened this issue Dec 4, 2021 · 5 comments
Assignees
Labels
enhancement New feature or request in-NEW Changes are already available in NEW branch. Configure SCOOP_BRANCH to NEW to beta-test changes
Milestone

Comments

@Ash258
Copy link
Owner

Ash258 commented Dec 4, 2021

Something like this could be faster

if ($script:Imported) {
    return
}
$script:Imported = $false

...

$script:Imported = $true
@Ash258 Ash258 added the enhancement New feature or request label Dec 4, 2021
@Ash258 Ash258 added this to the Backlog milestone Dec 4, 2021
@Ash258 Ash258 self-assigned this Dec 4, 2021
@Ash258 Ash258 changed the title Experiment with better "module" import Experiment with better "module" import guards Dec 4, 2021
Ash258 added a commit that referenced this issue Jan 22, 2022
- [ ] Test functionality
- [ ] Measuer container performance
- [ ] Test *nix

#238
Ash258 added a commit that referenced this issue Jan 28, 2022
@Ash258 Ash258 modified the milestones: Backlog, 0.6.5 Jan 28, 2022
@Ash258 Ash258 added the in-NEW Changes are already available in NEW branch. Configure SCOOP_BRANCH to NEW to beta-test changes label Jan 28, 2022
@ZzZombo
Copy link

ZzZombo commented Jan 31, 2022

Why do you seem to reinvert the wheel? Why not use the build-in module features like Import-Module, etc? These do not require such a thing like an "import guard", PowerShell will import only one instance of a module unless you create a very specific scenario.

@Ash258
Copy link
Owner Author

Ash258 commented Jan 31, 2022

And who will cleanup the leaked modules? All of the functions would leak into current powershell user session. And on repeated command it would conflict.

If user would run shovel update, it would not work, as the module would be loaded, which would prevent the update from removing/updating files.

@Ash258
Copy link
Owner Author

Ash258 commented Jan 31, 2022

/preblock

@ZzZombo
Copy link

ZzZombo commented Jan 31, 2022

You can unload modules with Remove-Module at the end of the current activity, or you can load them locally, then you do not have to do this. And like I said earlier, PowerShell will not load the same module more than once (per session), so there is no conflict possible. Also, modules are loaded entirely in memory, and no locks are placed, so it's still possible to change any files. As long as a module is loaded, it's backing files can be changed as you wish cleanly, and only after unloading and importing it again the changes take effect.

@Ash258
Copy link
Owner Author

Ash258 commented Jan 31, 2022

In ideal case yes. But not in all. CTRL+C, fails, everything would have to run remove-module. Not possible to achieve.

The conflict would occour on update. The new functions (with new code) would not be loaded, as they would be already loaded, -Force needs to be used, which is not convenient for all cases.

Complete waste of time to discuss more. Not talking I just do not want to have it like that.

Repository owner locked and limited conversation to collaborators Jan 31, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request in-NEW Changes are already available in NEW branch. Configure SCOOP_BRANCH to NEW to beta-test changes
Projects
None yet
Development

No branches or pull requests

2 participants