@@ -34,8 +34,9 @@ import Data.Function.Uncurried (Fn2, runFn2)
3434import Data.HTTP.Method (Method (..), CustomMethod )
3535import Data.HTTP.Method as Method
3636import Data.List.NonEmpty as NEL
37- import Data.Maybe (Maybe (..))
37+ import Data.Maybe (Maybe (..), fromMaybe )
3838import Data.Nullable (Nullable , toNullable )
39+ import Data.Time.Duration (Milliseconds (..))
3940import Effect.Aff (Aff , try )
4041import Effect.Aff.Compat as AC
4142import Effect.Exception as Exn
@@ -56,6 +57,7 @@ type Request a =
5657 , password :: Maybe String
5758 , withCredentials :: Boolean
5859 , responseFormat :: ResponseFormat.ResponseFormat a
60+ , timeout :: Maybe Milliseconds
5961 }
6062
6163-- | A record of the type `Request` that has all fields set to default
@@ -79,6 +81,7 @@ defaultRequest =
7981 , password: Nothing
8082 , withCredentials: false
8183 , responseFormat: ResponseFormat .ignore
84+ , timeout: Nothing
8285 }
8386
8487-- | The possible errors that can occur when making an Affjax request.
@@ -197,6 +200,7 @@ request req =
197200 , username: toNullable req.username
198201 , password: toNullable req.password
199202 , withCredentials: req.withCredentials
203+ , timeout: fromMaybe 0.0 $ (\(Milliseconds x) -> x) <$> req.timeout
200204 }
201205
202206 extractContent :: RequestBody.RequestBody -> Either String Foreign
@@ -251,6 +255,7 @@ type AjaxRequest a =
251255 , username :: Nullable String
252256 , password :: Nullable String
253257 , withCredentials :: Boolean
258+ , timeout :: Number
254259 }
255260
256261foreign import _ajax
0 commit comments