### Question:
IOResource implements AutoCloseable { @Override public void close() { release.accept(resource); } IOResource(T resource, Consumer1<? super T> release); IO<R> apply(Function1<? super T, ? extends IO<? extends R>> use); @Override void close();  }### Answer:
@Test public void bracket() throws SQLException { ResultSet resultSet = mock(ResultSet.class); when(resultSet.getString("id")).thenReturn("value"); IO<Try<String>> bracket = IO.bracket(open(resultSet), IO.lift(tryGetString("id"))); assertEquals(Try.success("value"), bracket.unsafeRunSync()); verify(resultSet).close(); }
@Test public void bracketAsync() throws SQLException { ResultSet resultSet = mock(ResultSet.class); when(resultSet.getString("id")).thenReturn("value"); IO<Try<String>> bracket = IO.bracket(open(resultSet), IO.lift(tryGetString("id"))); Future<Try<String>> future = bracket.foldMap(FutureInstances.async()).fix(toFuture()); assertEquals(Try.success("value"), future.await().get()); verify(resultSet, timeout(1000)).close(); }