# exit static method

Future<int> exit(

1. ApplicationContext context,
2. List<ExitCodeGenerator> exitCodeGenerators

)

Gracefully exits the application with the appropriate exit code.

This method:

1. Collects exit code from all registered exit code generators
2. Publishes an exit code event
3. Closes the application context
4. Returns the determined exit code

`context` the application context to close `exitCodeGenerators` additional exit code generators

Returns the exit code for the application

## Implementation

    static Future<int> exit(ApplicationContext context, List<ExitCodeGenerator> exitCodeGenerators) async {
    		int exitCode = 0;
      final cls = Class<ExitCodeGenerator>(null, PackageNames.MAIN);

    		try {
    			try {
    				final generators = ExitCodeGenerators();
          final result = await context.getPodsOf<ExitCodeGenerator>(cls);

    				final pods = result.values.toList();
    				generators.addAllGenerators(exitCodeGenerators);
    				generators.addAllGenerators(pods);

    				exitCode = generators.getExitCode();

    				if (exitCode != 0) {
    					context.publishEvent(ExitCodeEvent(context, exitCode));
    				}
    			} finally {
    				close(context);
    			}
    		} on Exception catch (ex) {
    			ex.printStackTrace();
    			exitCode = (exitCode != 0) ? exitCode : 1;
    		}

    		return exitCode;
    }