Skip to content

project-snail/snail-defer-spring-boot-starter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 

Repository files navigation

snail-defer-starter

使java支持defer和recover方法

开启defer操作

<dependency>
    <groupId>io.github.project-snail</groupId>
    <artifactId>snail-defer-starter</artifactId>
    <version>1.1</version>
</dependency>
snail:
  defer:
    enable: true

另外可以在类或方法上标识 @Deferrable 即可让此作用域支持操作

import static com.snail.defer.DeferUtil.defer;

@Deferrable
@Component
public class FooComponent {

    @Deferrable
    public Pair<Integer, String> handler() {

        DeferUtil.defer(
            () -> {
//                do something
            }
        );

        defer(
            () -> {
//                do something
            }
        );

        DeferUtil.recover(
            err -> Pair.of(1, "1")
        );

//                    zero err
        return Pair.of(1 / 0, "1");

    }

}

About

使java支持defer和recover操作 使用aop实现

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages