Skip to content

Latest commit

 

History

History
42 lines (34 loc) · 901 Bytes

File metadata and controls

42 lines (34 loc) · 901 Bytes
title DisposedBeforeAsyncRunAnalyzer
category analyzers
categoryindex 1
index 11

DisposedBeforeAsyncRunAnalyzer

Problem

A use statement in an async or task returning function can be problematic as the value is disposed before the returned workflow is run.

let f () =
    use t = new DisposableThing()
    async {
        return "hi"
    }

Fix

If applicable to your context, move the use statement into the async.

let f () =
    async {
        use t = new DisposableThing()
        return "hi"
    }

If the use before the async is really your intent, you can disable the warning with a line comment on top of the use statement containing disposed before returned workflow runs.

let f () =
    // Note: disposed before returned workflow runs
    use t = new DisposableThing()
    async {
        return "hi"
    }