Skip to content

Commit

Permalink
fix: AzureFunction implements AutoCloseable (#67)
Browse files Browse the repository at this point in the history
  • Loading branch information
sdelamo committed Sep 14, 2020
1 parent e26da7e commit e9c3a44
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
Expand Up @@ -16,15 +16,19 @@
package io.micronaut.azure.function;

import io.micronaut.context.ApplicationContext;
import io.micronaut.context.ApplicationContextProvider;
import io.micronaut.context.env.Environment;

import java.io.Closeable;
import java.io.IOException;

/**
* A base Azure function class that sets up the Azure environment and preferred configuration.
*
* @author graemerocher
* @since 1.0.0
*/
public abstract class AzureFunction {
public abstract class AzureFunction implements ApplicationContextProvider, Closeable {
protected static ApplicationContext applicationContext;

static {
Expand All @@ -42,6 +46,19 @@ public void run() {
}));
}

@Override
public ApplicationContext getApplicationContext() {
return this.applicationContext;
}

@Override
public void close() throws IOException {
if (applicationContext != null) {
applicationContext.close();
applicationContext = null;
}
}

/**
* Default constructor.
*/
Expand Down
@@ -0,0 +1,15 @@
package io.micronaut.azure.function

import spock.lang.Specification

class AzureFunctionSpec extends Specification {

void "AzureFunction implements AutoCloseable"() {
expect:
new FooFunction() instanceof AutoCloseable
}

static class FooFunction extends AzureFunction {

}
}

0 comments on commit e9c3a44

Please sign in to comment.