How to isolate your program from calls to a “bad” API?

后端 未结 4 1485
走了就别回头了
走了就别回头了 2020-12-15 09:48

When I developed a piece of (academic) software using Java, I was forced to use an API that was rather badly implemented. This means that calls to this API for a certain set

4条回答
  •  半阙折子戏
    2020-12-15 10:14

    I'm a big fan of separate processes for this kind of thing.

    Spawn a sub process and wait for results.

    If the API is non-deterministic, put the timer thread in a wrapper that makes the bad API into a main program.

    That way, the subprocess always ends within the given time. It either produces a useful result or a system exit code that indicates failure.

提交回复
热议问题