mirror of
https://github.com/facebook/Haxl.git
synced 2024-10-04 06:07:32 +03:00
5f2ebd2580
Summary: Pull Request resolved: https://github.com/facebook/Haxl/pull/99 This adds unit tests to haxl, to make sure we are tracking the outgone fetches correctly.. Reviewed By: simonmar Differential Revision: D14683672 fbshipit-source-id: 49a318f0b8aa38c2af154fcbe0946122e70b9565
47 lines
1.2 KiB
Haskell
47 lines
1.2 KiB
Haskell
-- Copyright (c) 2014-present, Facebook, Inc.
|
|
-- All rights reserved.
|
|
--
|
|
-- This source code is distributed under the terms of a BSD license,
|
|
-- found in the LICENSE file.
|
|
|
|
{-# LANGUAGE DeriveDataTypeable #-}
|
|
{-# LANGUAGE GADTs #-}
|
|
{-# LANGUAGE MultiParamTypeClasses #-}
|
|
{-# LANGUAGE OverloadedStrings #-}
|
|
{-# LANGUAGE StandaloneDeriving #-}
|
|
{-# LANGUAGE TypeFamilies #-}
|
|
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
|
|
{-# LANGUAGE FlexibleInstances #-}
|
|
|
|
module SleepDataSource (
|
|
Sleep, sleep,
|
|
) where
|
|
|
|
import Haxl.Prelude
|
|
import Prelude ()
|
|
|
|
import Haxl.Core
|
|
import Haxl.DataSource.ConcurrentIO
|
|
|
|
import Control.Concurrent
|
|
import Data.Hashable
|
|
import Data.Typeable
|
|
|
|
sleep :: Int -> GenHaxl u w Int
|
|
sleep n = dataFetch (Sleep n)
|
|
|
|
data Sleep deriving Typeable
|
|
instance ConcurrentIO Sleep where
|
|
data ConcurrentIOReq Sleep a where
|
|
Sleep :: Int -> ConcurrentIOReq Sleep Int
|
|
|
|
performIO (Sleep n) = threadDelay (n*1000) >> return n
|
|
|
|
deriving instance Eq (ConcurrentIOReq Sleep a)
|
|
deriving instance Show (ConcurrentIOReq Sleep a)
|
|
|
|
instance ShowP (ConcurrentIOReq Sleep) where showp = show
|
|
|
|
instance Hashable (ConcurrentIOReq Sleep a) where
|
|
hashWithSalt s (Sleep n) = hashWithSalt s n
|